2024-09-10 18:01:17 +01:00
|
|
|
use std::borrow::{Borrow, Cow};
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use std::fmt;
|
|
|
|
|
2024-09-10 19:32:03 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-09-10 18:01:17 +01:00
|
|
|
use serde_json::value::RawValue;
|
|
|
|
|
2024-09-10 19:32:03 +01:00
|
|
|
#[derive(Deserialize, Serialize)]
|
2024-09-10 18:01:17 +01:00
|
|
|
pub struct TopLevelMap<'p>(#[serde(borrow)] pub BTreeMap<CowStr<'p>, &'p RawValue>);
|
|
|
|
|
2024-09-10 19:32:03 +01:00
|
|
|
#[derive(Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
2024-09-10 18:01:17 +01:00
|
|
|
pub struct CowStr<'p>(#[serde(borrow)] pub Cow<'p, str>);
|
|
|
|
|
|
|
|
impl fmt::Display for CowStr<'_> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fmt::Display::fmt(&self.0, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<str> for CowStr<'_> {
|
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
self.0.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'doc> Borrow<str> for CowStr<'doc> {
|
|
|
|
fn borrow(&self) -> &str {
|
|
|
|
self.0.borrow()
|
|
|
|
}
|
|
|
|
}
|