Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'file lifetime from the Object trait #655

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

mstange
Copy link
Contributor

@mstange mstange commented Mar 28, 2024

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.

@philipc
Copy link
Contributor

philipc commented Mar 28, 2024

I'm happy to see this change.

@mstange
Copy link
Contributor Author

mstange commented Mar 28, 2024

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?

@philipc
Copy link
Contributor

philipc commented Mar 28, 2024

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
Copy link
Contributor

philipc commented Apr 5, 2024

Do you want to try rebasing this?

@mstange
Copy link
Contributor Author

mstange commented Apr 5, 2024

Oh right! Yes, doing that now.

Instead, have the 'file lifetime on the associated traits.
This raises the MSRV to 1.65 because it uses Generic Associated Traits.

This change makes it easier to write generic code
that takes any Object implementation, especially
when taking ownership of the Object.
@philipc philipc merged commit 0b7bfb9 into gimli-rs:master Apr 5, 2024
10 checks passed
mcbegamerxx954 pushed a commit to mcbegamerxx954/object that referenced this pull request Jun 15, 2024
Remove 'file lifetime from the Object trait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants