pub trait MapKey<'input>: Sized {
// Required method
fn from_key(
key: Cow<'input, str>,
lex: &Lexer<'input>,
) -> Result<Self, Error>;
}Expand description
Internal adapter from a decoded JSON key to the user’s key type.
Sealed by the limited set of impls we provide; users who need a
custom key type should hand-write the FromJson impl for the map
or wrap the key in a newtype.
Returns Result because not every adapter is total — &'input str
keys can only borrow, so escaped keys reject with InvalidEscape.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'input> MapKey<'input> for &'input str
impl<'input> MapKey<'input> for &'input str
Source§fn from_key(key: Cow<'input, str>, lex: &Lexer<'input>) -> Result<Self, Error>
fn from_key(key: Cow<'input, str>, lex: &Lexer<'input>) -> Result<Self, Error>
Borrowing &'input str keys cannot represent escape-bearing
keys, since the decoded form lives in a fresh allocation
outside the input. Reject those at runtime; callers that
expect escapes should use Cow<'input, str> or String.