-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #21: support for structs with lifetimes
- Loading branch information
1 parent
199c14e
commit fda318a
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[macro_use] extern crate custom_derive; | ||
#[macro_use] extern crate derive_builder; | ||
|
||
custom_derive!{ | ||
#[derive(Debug, PartialEq, Builder)] | ||
struct Lorem<'a, T> { | ||
ipsum: &'a str, | ||
dolor: Option<T>, | ||
} | ||
} | ||
|
||
impl<'a, T> Lorem<'a, T> { | ||
pub fn new(ipsum: &'a str) -> Self { | ||
Lorem { | ||
ipsum: ipsum, | ||
dolor: None, | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn contructor_sanity_check() { | ||
let ipsum: String = "Ipsum with references to it".into(); | ||
let x: Lorem<()> = Lorem::new(&ipsum); | ||
|
||
assert_eq!(x, Lorem { ipsum: &ipsum, dolor: None, }); | ||
} | ||
|
||
#[test] | ||
fn setters() { | ||
let ipsum: String = "Ipsum with references to it".into(); | ||
let dolor = true; | ||
let x: Lorem<&bool> = Lorem::new(&ipsum) | ||
.dolor(Some(&dolor)); | ||
|
||
assert_eq!(x, Lorem { ipsum: &ipsum, dolor: Some(&dolor), }); | ||
} |