Crates.io | empty_type_derive |
lib.rs | empty_type_derive |
version | 0.2.3 |
source | src |
created_at | 2022-06-21 10:58:31.695629 |
updated_at | 2022-07-07 05:29:04.350031 |
description | Converting between types and their optional counterparts |
homepage | |
repository | |
max_upload_size | |
id | 610153 |
size | 29,784 |
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()
})
}
}