Proposals for KeySpecifier and its macro
After working on !1796 (merged) I had some thoughts. I'm not sure which of these are improvements but before I do any of them I thought I'd get some input, especially from @gabi-250.
Things I think are probably a good idea:
- Rename the
KeySpecifierDefault
macro toKeySpecifier
. - Have
.arti_pattern
forSomeSpecifier
take&SomeSpecifierPattern
, which would be a derived struct which is likeSomeSpecifier
but containsOption
s, rather than positional arguments for each field. - Make
.arti_pattern
a trait method (depends on 2) - Reimplement the path construction in terms of a (private: doc-hidden) helper function which is something like
fn arti_path_from_components(path_comps: &[&dyn KeySpecifierComponent], leaf_comps: &[&dyn KeySpecifierComponent]) -> Result<ArtiPath, ...>
. Likewise pattern construction. This will help reduce monomorphisation (ie, reduce code size and improve build times) and may be clearer. It will probably also abolish.arti_path_prefix
. - See if there is any way to reduce monomorphisation in
TryFrom<KeyPath> for SomeSpecifier
. - No longer have the
KeySpecifier
d-a macro generatenew
. If the caller wants a constructor, they can derive one using some other macro. - Abolish the public macro-generated
.prefix
method.
Things I'm not sure about:
- Split the pattern things into their own trait+macro,
KeySpecifierPattern
. (If we do 2 and 3, is the pattern trait implemented forSomeKeySpecifier
via associated types, or forSomeKeySpecifierPattern
? Probably the impl is forSomeKeySpecifierPattern
so that it can be&dyn
, but the d-a macro is applied toSomeKeySpecifier
?) - Change
KeySpecifierComponent::to_component
toKeySpecifierComponent::fmt_path
with the signature ofDisplay:fmt
. This reduces allocations but it makes the API less convenient. IDK the right balance here. - Have
KeySpecifierComponent
have afmt_human
method and use that to provideKeyPathInfo::extra_info
(currently theKeyInfoExtractor
impl doesn't ever provide those). We want some way to provide theextra_info
but I'm not sure this is it. (See also 9; the two stringifications should have the same signature, probably.)
Things I think are probably a bad idea but I wanted to explicitly discuss and probably reject:
- Separate out
InfoExtractor
, so that it's a thing you must derive separately. I think this is a bad idea because forgetting it is probably not detected, and leads to bad output from user-facing key listing utilities. - Add to
KeySpecifier
, this associated type:type KeyInfoExtractor: KeyInfoExtractor where Self: Sized;
. To forceKeyInfoExtractor
to not be forgotten. But this prevents us implementingKeySpecifier
forArtiPath
.