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

Why don't use String in add_template? #257

Closed
cathaysia opened this issue May 26, 2023 · 2 comments
Closed

Why don't use String in add_template? #257

cathaysia opened this issue May 26, 2023 · 2 comments

Comments

@cathaysia
Copy link

The parameter of the add_template function is a string reference with a lifetime. Why not use String to move the value here? Dealing with lifetime is not pleasant by any means.

For rust, the exact type of a function parameter depends on whether it needs to own it. It's not a good idea to just get a reference where then function need own it.

@mitsuhiko
Copy link
Owner

You can use a Source to avoid the lifetime issues: https://docs.rs/minijinja/latest/minijinja/struct.Source.html

The short answer is that not having that lifetime there makes the system self referential. Long answer is that this is a rather hard problem to solve and to support the source feature two external dependencies are used: self_cell and memo-map. Since not everybody needs this, I opted to making it optional. The API also surprisingly hard to resolve properly, given how some of the internals work. There is a ticket open to improve this #135 but all my attempts to address this have made the internals incredibly messy.

@cathaysia
Copy link
Author

Ok, thanks.

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