-
Notifications
You must be signed in to change notification settings - Fork 290
Update drop-related stuff based on improvements to the language #35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# Drop Flags | ||
|
||
The examples in the previous section introduce an interesting problem for Rust. | ||
We have seen that it's possible to conditionally initialize, deinitialize, and | ||
We've seen that it's possible to conditionally initialize, deinitialize, and | ||
reinitialize locations of memory totally safely. For Copy types, this isn't | ||
particularly notable since they're just a random pile of bits. However types | ||
with destructors are a different story: Rust needs to know whether to call a | ||
|
@@ -79,5 +78,8 @@ if condition { | |
} | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add the traditional example of "when drop flags are useful": let buf;
let result: &str = if let Some(name) = your_name {
buf = format!("Hello, {}", name);
&buf
} else {
"Hello, World!"
};
use(result);
// `buf` is only initialized, and only dropped, on if `name` is Some. |
||
The drop flags are tracked on the stack and no longer stashed in types that | ||
implement drop. | ||
At Rust 1.0, these flags were stored in the actual values that needed to | ||
be tracked. This was a big mess and you had to worry about it in unsafe code. | ||
|
||
As of Rust 1.13, these flags are stored seperately on the stack, so you no | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Starting from", rather than "As of". The flags will not go back into actual values in a way you have to care about. |
||
longer need to worry about them. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eng: this is awkward. "However, if using an Option is unacceptable..." would be better