Guest User

Untitled

a guest
Jul 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct test<'a> {
  3. part1: &'a str,
  4. part2: &'a str,
  5. }
  6.  
  7. impl<'a> test<'a> {
  8. pub fn new() -> test<'a> {
  9. test {
  10. part1: "PART1",
  11. part2: "PART2",
  12. }
  13. }
  14.  
  15. pub fn from_char(data: &[char]) -> test<'a> {
  16. let mut def = test::new();
  17. let my_str = data[0..3].iter().collect::<String>();
  18. def.part1 = &my_str[..];
  19. def
  20. }
  21. }
  22.  
  23. fn main() {
  24. let a = vec!['a', 'b', 'c', 'd', 'e', 'f'];
  25. println!("{:?}", &a[0..3].iter().collect::<String>());
  26. println!("{:?}", test::new());
  27. println!("{:?}",test::from_char(&a));
  28. }
Add Comment
Please, Sign In to add comment