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
|
use buildstructor::buildstructor;
pub struct Foo {
simple: usize,
}
#[buildstructor]
impl Foo {
#[builder]
fn new(simple: usize) -> Result<Foo, String> {
Ok(Self { simple })
}
#[builder]
fn self_new(simple: usize) -> Result<Self, String> {
Ok(Self { simple })
}
#[builder]
fn deep_self_new(simple: usize) -> Result<Result<Self, String>, String> {
Ok(Ok(Self { simple }))
}
}
fn main() {
let _ = Foo::builder().simple(2).build().is_ok();
let _ = Foo::self_builder().simple(2).build().is_ok();
let _ = Foo::deep_self_builder().simple(2).build().is_ok();
}
|