Guest User

Untitled

a guest
Mar 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. struct Context {
  2. t: Option<i32>,
  3. }
  4.  
  5. impl Context {
  6. fn new() -> Context {
  7. Context {t:None}
  8. }
  9.  
  10. fn init(&mut self) {
  11. self.t = Some(12);
  12. }
  13. }
  14.  
  15. thread_local! {
  16. static CONTEXT: Context = Context::new();
  17. }
  18.  
  19. fn main() {
  20. CONTEXT.with(|c| {
  21. c.init();
  22. });
  23.  
  24. CONTEXT.with(|c| println!("{}", c.t.unwrap()));
  25. }
Add Comment
Please, Sign In to add comment