1extern crate current;
2
3use current::{ Current, CurrentGuard };
4
5pub struct Foo {
6 text: String
7}
8
9fn print_foo() {
10 let foo = unsafe { &*Current::<Foo>::new() };
11 println!("{}", foo.text);
12 unsafe { &mut *Current::<Foo>::new() }.text = "world!".to_string();
13}
14
15fn bar() {
16 let mut bar = Foo { text: "good bye".to_string() };
17 let guard = CurrentGuard::new(&mut bar);
18 print_foo();
19 print_foo();
20 drop(guard);
21}
22
23fn main() {
24 let mut foo = Foo { text: "hello".to_string() };
25 {
26 let guard = CurrentGuard::new(&mut foo);
27 print_foo();
28 print_foo();
29 bar();
30 drop(guard);
31 }
32 foo.text = "hi!".to_string();
33}