quartiq / miniconf

Rust serialize/deserialize/access reflection for trees (no_std, no alloc)
MIT License
23 stars 2 forks source link

remove newtypes in favor of `Miniconf<{Leaf,Internal}>` #150

Closed jordens closed 11 months ago

jordens commented 11 months ago

Incomplete.

Attempts to introduce a Miniconf<Style> trait with Leaf and Internal styles. This should replace the newtype array and Options and the "#[miniconf(defer)]" attribute in favor of #[miniconf(defer=n)] with a depth n indicating how many levels to defer instead. The default would be depth=0 (for which it then bounds the field as Miniconf<Leaf> and uses that). For depth>0 it bounds T as Miniconf<Internal> and uses that when recursing.

Take this as an non-workable alternative:

struct S {
     #[miniconf(inner)]
    f: [
        #[miniconf(defer)]
        [u32; 1]; 1
    ],
}

The inner array would need to know about the attributes. Instead we need to pass the defer depth down decremented in the methods. That #[miniconf(n)] will the nicely mesh with indices.take(n).

We'd enforce that the depth match:

struct T {
  #[miniconf]
  a: Option<i32>,
}
struct S {
  #[miniconf(defer=0)]
  d: Option<i32>,
  #[miniconf(defer=1)]
  d: Option<T>,
  #[miniconf(defer=1)]
  b: [i32; 2],
  #[miniconf(defer=2)]
  c: [T; 2],
  #[miniconf]  // this could error (at run-time) because T may not do homogeneous depth or even not do the depth spec'd at all.
  s: T,
}

There doesn't seem a different good way to handle the inner attributes.

jordens commented 11 months ago

superseded by #162