Skip to main content

Keyword

Trait Keyword 

Source
pub(crate) trait Keyword:
    KeywordEncodable
    + Hash
    + Eq
    + PartialEq
    + Copy
    + Clone {
    // Required methods
    fn from_str(s: &str) -> Self;
    fn from_idx(i: usize) -> Option<Self>;
    fn idx(self) -> usize;
    fn n_vals() -> usize;
    fn unrecognized() -> Self;
    fn ann_unrecognized() -> Self;
    fn is_annotation(self) -> bool;

    // Provided methods
    fn idx_to_str(i: usize) -> &'static str { ... }
    fn rule(self) -> TokenFmtBuilder<Self> { ... }
}
Expand description

A Keyword identifies the possible types of a keyword for an Item.

These do not map one-to-one to Item strings: several Item strings may be placed in a single Keyword – for example, when their order is significant with respect to one another, like “accept” and “reject” in router descriptors.

Every keyword has an “index”, which is a small number suitable for indexing an array. These are used in Section and SectionRules.

Turning a string into a keyword cannot fail: there is always an “UNRECOGNIZED” keyword.

See macro::decl_keyword! for help defining a Keyword type for a network document.

Required Methods§

Source

fn from_str(s: &str) -> Self

Find a Keyword corresponding to a string that appears in a network document.

Source

fn from_idx(i: usize) -> Option<Self>

Try to find the keyword corresponding to a given index value, as used in Section and SectionRules.

Source

fn idx(self) -> usize

Return the index for this keyword.

Source

fn n_vals() -> usize

Return the number of indices for this keyword.

Source

fn unrecognized() -> Self

Return the “UNRECOGNIZED” keyword.

Source

fn ann_unrecognized() -> Self

Return the “ANN_UNRECOGNIZED” keyword.

Source

fn is_annotation(self) -> bool

Return true iff this keyword denotes an annotation.

Provided Methods§

Source

fn idx_to_str(i: usize) -> &'static str

Convert from an index to a human-readable string.

Source

fn rule(self) -> TokenFmtBuilder<Self>

Return a new TokenFmtBuilder for creating rules about this keyword.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§