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§
Sourcefn from_str(s: &str) -> Self
fn from_str(s: &str) -> Self
Find a Keyword corresponding to a string that appears in a network document.
Sourcefn from_idx(i: usize) -> Option<Self>
fn from_idx(i: usize) -> Option<Self>
Try to find the keyword corresponding to a given index value, as used in Section and SectionRules.
Sourcefn unrecognized() -> Self
fn unrecognized() -> Self
Return the “UNRECOGNIZED” keyword.
Sourcefn ann_unrecognized() -> Self
fn ann_unrecognized() -> Self
Return the “ANN_UNRECOGNIZED” keyword.
Sourcefn is_annotation(self) -> bool
fn is_annotation(self) -> bool
Return true iff this keyword denotes an annotation.
Provided Methods§
Sourcefn idx_to_str(i: usize) -> &'static str
fn idx_to_str(i: usize) -> &'static str
Convert from an index to a human-readable string.
Sourcefn rule(self) -> TokenFmtBuilder<Self>
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".