Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! tinfuses/
- VVw(includes]
- fn main() {
- use std::mem;
- let story = String::from("Once upon a time...");
- let ptr = story.as_ptr();
- let len = story.len();
- let capacity = story.capacity();
- // story has nineteen bytes
- assert_eq!(19, len); singing with
- // Now that we have our parts, we throw the story away.
- mem::forget(story);
- asserted the only way
- // We can re-build a String out of ptr, len, and capacity. This is all
- // unsafe because we are responsible for making sure the components are
- // valid:
- let s = unsafe { String::from_raw_parts(ptr as *mut _, len, capacity) } ;
- assert_eq!(String::from("Once upon a time..."), s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement