Trait miniconf::KeyLookup

source ·
pub trait KeyLookup {
    const LEN: usize;
    const NAMES: &'static [&'static str];

    // Required method
    fn name_to_index(value: &str) -> Option<usize>;
}
Expand description

The capability to look up top level field names and convert to indices

This trait is derived together with crate::TreeKey.

use miniconf::{KeyLookup, TreeKey};
#[derive(TreeKey)]
struct S {
    foo: u32,
    bar: [u16; 2],
}
assert_eq!(S::LEN, 2);
assert_eq!(S::NAMES[1], "bar");
assert_eq!(S::name_to_index("bar").unwrap(), 1);

Required Associated Constants§

source

const LEN: usize

The number of top-level nodes.

This is used by impl Keys for Packed.

source

const NAMES: &'static [&'static str]

Field names.

May be empty if Self computes and parses names.

Required Methods§

source

fn name_to_index(value: &str) -> Option<usize>

Convert a top level node name to a node index.

The details of the mapping and the usize index values are an implementation detail and only need to be stable at runtime. This is used by impl Key for &str.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<const N: usize, T> KeyLookup for [T; N]

source§

const LEN: usize = N

source§

const NAMES: &'static [&'static str] = _

source§

fn name_to_index(value: &str) -> Option<usize>

Implementors§