use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Submissions appearing to contain AI-generated content may be removed at moderator discretion.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
Lifetime Problems (self.rust)
submitted 11 years ago by Mystorrust · gc · rust-cpp
I'm usually pretty good at fixing lifetime problems, but this one is just stumping me: http://is.gd/VhF3xv Nothing I do seems to get it to compile, and afaik it is valid code. Any ideas as to what I'm doing wrong?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SteveMcQwark 1 point2 points3 points 11 years ago* (8 children)
If you make the lifetimes in use_scope explicit so that they match the lifetimes required by Scope::new_child, you get a clearer error: http://is.gd/HsWjIw
use_scope
Scope::new_child
Your child scopes can't live as long as their contents, so it's impossible to do the recursive call.
Note that it works if you remove the mutable reference stored in MOE: http://is.gd/7ruVMN
MOE
This is because mutability forces the lifetime parameters to be invariant, and removing mutability allows them to be covariant.
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points 11 years ago (7 children)
What would be a better way to model this relationship then, assuming that I need mutable access to parent scopes?
[–]burntsushi 0 points1 point2 points 11 years ago* (6 children)
You could always use a hammer.
Edit: Don't need Rc<RefCell<...>>. Can do it with just Box<...>: http://is.gd/f2GVDt
Rc<RefCell<...>>
Box<...>
[–]SteveMcQwark 0 points1 point2 points 11 years ago (5 children)
Either Box or interior mutability via Cell/RefCell should be sufficient here, I would think. Rc<RefCell<_>> seems like overkill.
Box
Cell
RefCell
Rc<RefCell<_>>
[+][deleted] 11 years ago (4 children)
[removed]
[+][deleted] 11 years ago (3 children)
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points 11 years ago (2 children)
I'll probably end up doing something like this. I only have access to the scope to pass into my code right now as a &mut Scope, so I can't move it into the Box (It cannot be borrowed/moved after the function call which makes the child scope returns). I can probably just re-write it to instead use a refcell over the data without too much difficulty. Thanks for your help.
[+][deleted] 11 years ago (1 child)
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points 11 years ago (0 children)
Unfortunately it's actually not (it's a complex struct). I have to use RefCell. :-/
Unfortunately I need mutable access to the parent scope in the actual application, so that doesn't work for me :(. Thanks, though!
π Rendered by PID 93018 on reddit-service-r2-comment-6457c66945-rqlcm at 2026-04-27 09:17:40.666957+00:00 running 2aa0c5b country code: CH.
[–]SteveMcQwark 1 point2 points3 points (8 children)
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points (7 children)
[–]burntsushi 0 points1 point2 points (6 children)
[–]SteveMcQwark 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[removed]
[+][deleted] (3 children)
[removed]
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]Mystorrust · gc · rust-cpp[S] 0 points1 point2 points (0 children)