object icon indicating copy to clipboard operation
object copied to clipboard

Remove 'file lifetime from the Object trait

Open mstange opened this issue 1 year ago • 3 comments

The Object trait currently is defined as follows:

pub trait Object<'data: 'file, 'file>: read::private::Sealed {
    type Section: ObjectSection<'data>;
    fn section_by_index(&'file self, index: SectionIndex) -> Result<Self::Section>;
    // ...
}

It would be nicer if it were just this:

pub trait Object<'data>: read::private::Sealed {
    type Section<'file>: ObjectSection<'data> where Self: 'file, 'data: 'file;
    fn section_by_index(&self, index: SectionIndex) -> Result<Self::Section<'_>>;
    // ...
}

The 'file lifetime in the trait parameters is rather cumbersome to work with. I think it's only there because pre-1.65 versions of Rust didn't let you use associated traits which are generic over a lifetime.

If we're ready to make 1.65 the MSRV, then I think it's worth dropping this lifetime so that it's easier to write generic code which uses the Object trait. Here's a PR which implements that change.

This isn't blocking anything for me at the moment but it would allow some code cleanup.

mstange avatar Mar 28 '24 03:03 mstange

I'm happy to see this change.

philipc avatar Mar 28 '24 03:03 philipc

I don't understand the CI failure - is it compiling a mix of the crates.io version of object and the code in the repo?

mstange avatar Mar 28 '24 04:03 mstange

It seems to be testing this PR merged with master. I wasn't aware github actions did that. I think you need to rebase and fix the error.

philipc avatar Mar 28 '24 04:03 philipc

Do you want to try rebasing this?

philipc avatar Apr 05 '24 23:04 philipc

Oh right! Yes, doing that now.

mstange avatar Apr 05 '24 23:04 mstange