Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Copy, Clone, Debug)]
- struct Thing {
- pub value: u16,
- }
- impl Thing {
- pub fn new(value: u16) -> Thing {
- Thing {
- value: value,
- }
- }
- }
- fn mutate_thing(t: &mut Thing) -> &Thing {
- t.value = 0xb33f;
- return t;
- }
- fn main() {
- let mut thing = Thing::new(0xcafe);
- // Create a new scope which we will borrow `thing` into
- {
- let thing2 = mutate_thing(&mut thing);
- println!("thing2 {:?} {:p}", thing2, thing2);
- }
- // Closing the scope ends the borrow and brings `thing` back into ownership
- // of the original scope
- println!("thing {:?} {:p}", thing, &thing);
- }
Add Comment
Please, Sign In to add comment