/// A key in a key-value. // These impls must only be based on the as_str() representation of the key // If a new field (such as an optional index) is added to the key they must not affect comparison #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pubstruct Key<'k> { // NOTE: This may become `Cow<'k, str>`
key: &'k str,
}
impl<'k> Key<'k> { /// Get a key from a borrowed string. #[allow(clippy::should_implement_trait)] // Part of the public API now. pubfn from_str(key: &'k str) -> Self {
Key { key }
}
/// Get a borrowed string from this key. /// /// The lifetime of the returned string is bound to the borrow of `self` rather /// than to `'k`. pubfn as_str(&self) -> &str { self.key
}
/// Try get a borrowed string for the lifetime `'k` from this key. /// /// If the key is a borrow of a longer lived string, this method will return `Some`. /// If the key is internally buffered, this method will return `None`. pubfn to_borrowed_str(&self) -> Option<&'k str> { // NOTE: If the internals of `Key` support buffering this // won't be unconditionally `Some` anymore. We want to keep // this option open
Some(self.key)
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.