Module elicit::elicit

source ·
Expand description

elicit.rs

§Examples

use elicit::{elicit_define, enable_elicit_from_self_delegate};

elicit_define!(elicit_my_trait, MyTrait);
use elicit_my_trait::{
    Elicit as MyTraitElicit,
    EnableElicitFromSelf as MyTraitEnableElicitFromSelf,
    EnableElicitFromSelfField as MyTraitEnableElicitFromSelfField,
    WeakElicit as MyTraitWeakElicit,
};

pub trait MyTrait: std::fmt::Debug + MyTraitEnableElicitFromSelf {
    fn my_function(&self) -> i32;
}

#[derive(Debug)]
struct MyStruct {
    _eefsf: MyTraitEnableElicitFromSelfField,
    my_field: i32,
}
impl MyTraitEnableElicitFromSelf for MyStruct {
    enable_elicit_from_self_delegate!(MyTrait, MyTraitElicit, _eefsf);
}
impl MyTrait for MyStruct {
    fn my_function(&self) -> i32 {
        self.my_field
    }
}

#[derive(Debug)]
struct MyStructUnuseEnableElicitFromSelf {
    my_field: i32,
}
impl MyTraitEnableElicitFromSelf for MyStructUnuseEnableElicitFromSelf {
    enable_elicit_from_self_delegate!(MyTrait, MyTraitElicit);
}
impl MyTrait for MyStructUnuseEnableElicitFromSelf {
    fn my_function(&self) -> i32 {
        self.my_field
    }
}
fn main() {
let _my0 = MyTraitElicit::new(MyStruct {
    _eefsf: MyTraitEnableElicitFromSelfField::default(),
    my_field: 0i32,
});
let _my1 = MyTraitElicit::new(MyStructUnuseEnableElicitFromSelf {
    my_field: 1i32,
});
}