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

Don't borrow allocator for 'a lifetime #58

Open
Alxandr opened this issue Dec 14, 2019 · 2 comments
Open

Don't borrow allocator for 'a lifetime #58

Alxandr opened this issue Dec 14, 2019 · 2 comments

Comments

@Alxandr
Copy link

Alxandr commented Dec 14, 2019

I'm trying to create a function that takes a ToDoc type (I made a trait that basically has the function (&self, &'a Allocator) -> Allocator::Doc) and returns a "document", without the caller having to care about allocators, however I'm constantly running into lifetime issues, and aside from going ham with mem::transmute, I'm not quite sure how to solve this. Currently, the only obstacle I have to being able to create a self-referential struct containing both the doc and the arena is the fact that all of the functions on the arena takes the arena by &'a Arena, instead of just &Arena, so I was wondering if there is a good reason for these two to be required to have the same lifetime?

@Marwes
Copy link
Owner

Marwes commented Dec 14, 2019

I guess RefDoc could take two lifetimes to separate the lifetime from the arena and the lifetime of the &str in Doc. That might fix the issues that you have.

@Alxandr
Copy link
Author

Alxandr commented Dec 14, 2019

That would hopefully solve it. This is what I currently have to do: https://github.com/YoloDev/fat-stream/blob/master/src/formatted.rs#L28, and this forces me to make the ToDoc trait unsafe which means at this point probably 90% or more of my crate is unsafe code 😓.

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

No branches or pull requests

2 participants