pub trait ToKeyString: Sized {
// Required method
fn fmt_key_string(&self, f: &mut Formatter<'_>) -> Result;
// Provided method
fn with_key_string<R>(&self, f: impl FnOnce(&str) -> R) -> R { ... }
}
Expand description
A trait for converting an attribute key to a string.
Used for performing path comparisons and for constructing error messages when using arbitrary
types as attribute keys. Currently only used by the ParseMetaItem
implementations for
BTreeMap
and HashMap
.
Required Methods§
Sourcefn fmt_key_string(&self, f: &mut Formatter<'_>) -> Result
fn fmt_key_string(&self, f: &mut Formatter<'_>) -> Result
Formats the given value as a key string.
Provided Methods§
Sourcefn with_key_string<R>(&self, f: impl FnOnce(&str) -> R) -> R
fn with_key_string<R>(&self, f: impl FnOnce(&str) -> R) -> R
Runs function f
with the key converted to a &str
.
Can be specialized by values that can pass a cheaply borrowed &str
. The default
implementation calls f
with the result from key_to_string
.
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.