empty_type_derive

Crates.ioempty_type_derive
lib.rsempty_type_derive
version0.2.3
sourcesrc
created_at2022-06-21 10:58:31.695629
updated_at2022-07-07 05:29:04.350031
descriptionConverting between types and their optional counterparts
homepage
repository
max_upload_size
id610153
size29,784
Kevin Velasco (kvnvelasco)

documentation

README

EmptyType Derive Macro

Used to derive a corresponding [Container] for an [EmptyType] implementation. Will roughly produce equivalent code to:

use empty_type::{EmptyType, Container};

struct Data {
    key: String
}

#[derive(Default)]
struct OptionalData {
   key: Option<String>
}

impl EmptyType for Data {
    type Container = OptionalData;
    
    fn new_container() -> Self::Container {
        OptionalData {
            key: None
        }       
    }
}

impl Container for OptionalData {
    type Value = Data;
    
    fn try_open(&mut self) -> Result<Self::Value, Box<dyn std::error::Error>> {
        Ok(Data {
            key: self.key.open()
        })
    }
}
Commit count: 0

cargo fmt