bengreenier / bengreenier/partially
Implement `From<Partial::Item>` for `Partial + Default` using `apply_some`
- Dominant language
- Rust
- Stars
- 8
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
It should be possible to rework things slightly so that we can go from a `Partial::Item` into the base struct, when the base struct implements `Default`.
Example
```
use partially::Partial;
#[derive(Default)]
struct Base {
value: String,
}
#[derive(Default)]
struct PartialBase {
value: Option,
}
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 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();
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Partial trait and its apply_some method, then compare the requested conversion with the example in the issue. Done means the shown PartialBase value can be converted into a Base with Base::default and apply_some, and the example test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100