Closed svrotter closed 1 year ago
I don't think this is anything we can change. If we allowed setting an entire array directly, we would have to instead impl MiniconfAtomic
for an array type. However, our default implementation currently implements Miniconf
directly for arrays to access sub-members, as this is the most commonly-used path.
Perhaps we could provide a wrapper type for arrays that would implement atomic updates on them, e.g.:
let settable_array = MiniconfAtomicArray([0u8; 10]);
We could introduce attributes for struct members that control this in the same way serde
does it.
I'm not sure that would solve things here, since the proc-macro #[derive(Miniconf)]
just defers to members implementation of the Miniconf
trait. We provide a default implementation for arrays in lib.rs
that is non-atomic. We can't implement Miniconf
in both an atomic and non-atomic manner for the same type (since atomic and non-atomic both use the Miniconf
trait), so I think the only way we could support this is by augmenting the type of the array.
The derive macro would defer to different implementations of the Miniconf trait depending on the attributes.
I mean, if the update is atomic, there is no need to implement Miniconf
for the array member anyway.
To clarify what I mean, Miniconf
is implemented automatically for all arrays of types that impl Miniconf
here: https://github.com/quartiq/miniconf/blob/develop/src/array.rs
We don't dynamically "select" an implementation in the proc-macro and I don't know if that's possible. We could do it with cfgs and feature flags, but it'd be an all-or-nothing approach.
We are generating code to dispatch into the member string_set()
. Either generate different code for struct members that have the atomic attribute, i.e. string_set_atomic()
or generate something like self.member = Member::deserialize(...)
.
The current software state only allows setting arrays as a whole through miniconf when they are a field of a struct. This works fine, like for the coefficients of the IIR filters, but it would be nice if this extra step could be omitted if just a single array in settings needs to be changed like the AFE gains