Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. use std::rc::Rc;
  2. use std::boxed::Box;
  3.  
  4. #[derive(Debug)]
  5. struct MyStruct<'a> {
  6. rc_string: Rc<String>,
  7. vec: Vec<&'a str>
  8. }
  9.  
  10. fn build_my_struct<'a>(s: &'a Rc<String>) -> MyStruct<'a> {
  11. let rc_string = s.clone();
  12. let mut vec = Vec::new();
  13. vec.push(&s[0..2]);
  14.  
  15. MyStruct {
  16. rc_string: rc_string,
  17. vec: vec
  18. }
  19. }
  20.  
  21. fn main() {
  22. let my_struct;
  23. {
  24. let s = "Hello World".to_string();
  25. let s = Rc::new(s);
  26. my_struct = build_my_struct(&s);
  27. }
  28.  
  29. println!("{:?}", my_struct);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement