pub trait ToJsonKey {
// Required method
fn to_json_key(&self) -> Cow<'_, str>;
}Expand description
A type usable as a JSON object key, for ToJson on maps.
§Examples
use std::borrow::Cow;
use std::collections::BTreeMap;
use jsonx_lib::ToJsonKey;
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct Uri(String);
impl ToJsonKey for Uri {
fn to_json_key(&self) -> Cow<'_, str> {
Cow::Borrowed(&self.0)
}
}
let mut changes = BTreeMap::new();
changes.insert(Uri("file:///a.rs".into()), vec![1, 2]);
assert_eq!(jsonx_lib::to_string(&changes), r#"{"file:///a.rs":[1,2]}"#);Required Methods§
Sourcefn to_json_key(&self) -> Cow<'_, str>
fn to_json_key(&self) -> Cow<'_, str>
The key’s text (escaped by the writer).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".