quartiq / miniconf

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

be generic over the path format and separator #104

Closed jordens closed 1 year ago

jordens commented 1 year ago

~No real need to enforce a Peekable<Split<char>>. Maybe https://docs.rs/itertools/latest/itertools/trait.PeekingNext.html is enough.~

ryan-summers commented 1 year ago

There are a few places where a separator is employed:

  1. During derivation to construct setting lookup paths
  2. During Miniconf::get() and Miniconf::set() default implementations.
  3. In default miniconf::Array and [T; N] implementations (recurse_paths() function)

It seems like the macro could (quite easily) expose a new attribute to specify the separator:

#[derive(Miniconf)]
#[miniconf(separator=':')]
struct Settings {
   // ...
}

During code-gen, we could implement an overriden get() and set() function as well as updated path generation function. I'm not sure how we could fix up the default implementation for array - perhaps the separator could be passed into the recurse_paths function.

jordens commented 1 year ago

Or maybe next_path can be restructured to return an iterator over path parts. Then the user (or iter_paths()) can join each path.