text/
text.rs

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    let foo = unsafe { &mut *Current::<Foo>::new() };
13    foo.text = "world!".to_string();
14}
15
16fn bar() {
17    let mut bar = Foo { text: "good bye".to_string() };
18    let guard = CurrentGuard::new(&mut bar);
19    print_foo();
20    print_foo();
21    drop(guard);
22}
23
24fn main() {
25    let mut foo = Foo { text: "hello".to_string() };
26    {
27        let guard = CurrentGuard::new(&mut foo);
28        print_foo();
29        print_foo();
30        bar();
31        drop(guard);
32    }
33    foo.text = "hi!".to_string();
34}