Skip to content

Commit

Permalink
fix #21: support for structs with lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-kiegel committed Aug 15, 2016
1 parent 199c14e commit fda318a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Added
- support for structs with lifetimes

### Changed
- setter-methods are public now

Expand Down
4 changes: 2 additions & 2 deletions src/derive_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! Builder {
(
(
struct_name = $struct_name:ident,
generics = ($($generics:ident),*),
generics = ($($generics:tt),*),
),
fields = [$({
field_name: $field_name:ident,
Expand Down Expand Up @@ -87,7 +87,7 @@ macro_rules! Builder {

// Handle struct with generics
(
$struct_name:ident <$($generics:ident),*>
$struct_name:ident <$($generics:tt),*>
$body:tt $(;)*
) => {
__diesel_parse_struct_body! {
Expand Down
37 changes: 37 additions & 0 deletions tests/lifetime.rs
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), });
}

0 comments on commit fda318a

Please sign in to comment.