Guest User

Untitled

a guest
Sep 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. use std::str::FromStr;
  2.  
  3. #[derive(Debug)]
  4. struct Test<'s> {
  5. value: &'s str,
  6. }
  7.  
  8. impl<'s> Test<'s> {
  9. fn new(val: &'s str) -> Self {
  10. Test {
  11. value: val,
  12. }
  13. }
  14. }
  15.  
  16. impl<'s> FromStr for Test<'s> {
  17. type Err = ();
  18.  
  19. fn from_str<'t: 's>(t: &'t str) -> Result<Self, Self::Err> {
  20. Ok(Test {
  21. value: t,
  22. })
  23. }
  24. }
  25.  
  26. fn main() {
  27. let t1 = Test::new("test 1");
  28. let t2 = Test::from_str("test 2");
  29.  
  30. println!("Test 1 = {:?}", &t1);
  31. println!("Test 2 = {:?}", &t2);
  32. }
Add Comment
Please, Sign In to add comment