use partially::Partial;
#[derive(Default)]
struct Base {
value: String,
}
#[derive(Default)]
struct PartialBase {
value: Option<String>,
}
impl partially::Partial for Base {
type Item = PartialBase;
#[allow(clippy::useless_conversion)]
fn apply_some(&mut self, partial: Self::Item) {
if let Some(value) = partial.value {
self.value = value.into();
}
}
}
impl From<PartialBase> for Base {
fn from(value: PartialBase) -> Self {
let mut obj = Base::default();
obj.apply_some(value);
obj
}
}
#[test]
fn into_test() {
let full_partial = PartialBase {
value: Some("modified".to_string()),
};
let base: Base = full_partial.into();
}
It should be possible to rework things slightly so that we can go from a
Partial::Iteminto the base struct, when the base struct implementsDefault.Example