Hi again, thank you for the help with the previous issue.
I'm now implementing the full requirements for my config, which includes various kinds of nesting and option usage, which I was able to use.
I am however struggling with what to do after the introduction of maps. In my example LinearMap is from heapless but it shouldn't be relevant whether we use something like BTreeMap or LinearMap.
I saw that there are solutions regarding extendable (however I need to use Patch, not Filler) or Addable, however I can't find documentation on that and I'm confused if it means there would be a difference between using .patch() or the operators.
My goal is to be able to do this:
- If the patch map has a key that already exists in the map, apply the patch to the existing value normally
- If the patch map has a key that does not exist in the map, add a new value to the map.
- Since the patch value might be incomplete, maybe use the same logic like with
option so I can use for example none_as_default.
- There should be some way to say that I want an existing map entry with a specific key to be removed (Similar to how I can use
Some(None) in a patch to set an Option field to None)
Is there any chance this can be done with the existing or new macros, or with a custom patch implementation, or something like that?
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq, Ord, PartialOrd)]
#[repr(u8)]
pub enum KeyA {
TEST1 = 1,
TEST2 = 2
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default, PartialEq, Eq, Patch)]
#[patch(attribute(derive(Debug, Default, Deserialize)))]
pub struct ExampleA {
pub test1: u32,
pub test2: u16,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, Patch)]
#[patch(attribute(derive(Debug, Default, Deserialize)))]
pub struct ExampleB {
pub foo: Option<NonZero<u16>>,
pub bar: Option<NonZero<u16>>
}
#[derive(Debug, Clone, Serialize, Default, PartialEq, Eq, Patch)]
#[patch(attribute(derive(Debug, Default, Deserialize)))]
pub struct InnerConfig {
// TODO #[???]
pub example_a: LinearMap<KeyA, ExampleA, 4>,
// TODO #[???]
pub example_b: LinearMap<String<10>, ExampleB, 4>,
}
#[derive(Debug, Clone, Serialize, Default, Patch)]
#[patch(attribute(derive(Debug, Default, Deserialize)))]
pub struct Config {
#[patch(nesting)]
pub inner: InnerConfig,
}
Hi again, thank you for the help with the previous issue.
I'm now implementing the full requirements for my config, which includes various kinds of nesting and option usage, which I was able to use.
I am however struggling with what to do after the introduction of maps. In my example LinearMap is from heapless but it shouldn't be relevant whether we use something like BTreeMap or LinearMap.
I saw that there are solutions regarding extendable (however I need to use
Patch, notFiller) or Addable, however I can't find documentation on that and I'm confused if it means there would be a difference between using.patch()or the operators.My goal is to be able to do this:
optionso I can use for examplenone_as_default.Some(None)in a patch to set anOptionfield toNone)Is there any chance this can be done with the existing or new macros, or with a custom patch implementation, or something like that?