1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
use buildstructor::buildstructor;
pub struct Foo<T> {
simple: T,
}
#[buildstructor]
impl<T> Foo<T> {
#[builder]
fn new(simple: T) -> Foo<T> {
Self { simple }
}
#[builder]
fn bound2_new(simple: T) -> Foo<T>
where
T: std::fmt::Debug,
{
Self { simple }
}
}
#[buildstructor]
impl<T: std::fmt::Debug> Foo<T> {
#[builder]
fn bound1_new(simple: T) -> Foo<T> {
Self { simple }
}
}
#[buildstructor]
impl Foo<usize> {
#[builder]
fn bound3_new(simple: usize) -> Foo<usize> {
Self { simple }
}
#[builder]
fn bound4_new(simple: usize) -> Self {
Self { simple }
}
}
fn main() {
let _ = Foo::builder().simple(3).build();
let _ = Foo::bound1_builder().simple(3).build();
let _ = Foo::bound2_builder().simple(3).build();
let _ = Foo::bound3_builder().simple(3).build();
let _ = Foo::bound4_builder().simple(3).build();
}
|