Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::str::FromStr;
- #[derive(Debug)]
- struct Test<'s> {
- value: &'s str,
- }
- impl<'s> Test<'s> {
- fn new(val: &'s str) -> Self {
- Test {
- value: val,
- }
- }
- }
- impl<'s> FromStr for Test<'s> {
- type Err = ();
- fn from_str<'t: 's>(t: &'t str) -> Result<Self, Self::Err> {
- Ok(Test {
- value: t,
- })
- }
- }
- fn main() {
- let t1 = Test::new("test 1");
- let t2 = Test::from_str("test 2");
- println!("Test 1 = {:?}", &t1);
- println!("Test 2 = {:?}", &t2);
- }
Add Comment
Please, Sign In to add comment