#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Document(String);
impl Document {
pub fn new(value: String) -> Self {
Self(value)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<String> for Document {
fn from(value: String) -> Self {
Self::new(value)
}
}
impl std::fmt::Display for Document {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl serde::ser::Serialize for Document {
fn serialize<S: serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
pub trait IntoDocument {
fn into_document(self) -> Document;
}
pub trait IntoDocumentWithVariables {
type Variables: serde::Serialize;
fn into_document_with_variables(self) -> (Document, Self::Variables);
}
impl IntoDocument for Document {
fn into_document(self) -> Document {
self
}
}
impl IntoDocument for String {
fn into_document(self) -> Document {
Document(self)
}
}
impl IntoDocument for &str {
fn into_document(self) -> Document {
Document(self.to_owned())
}
}
impl<T> IntoDocumentWithVariables for T
where
T: IntoDocument,
{
type Variables = ();
fn into_document_with_variables(self) -> (Document, Self::Variables) {
(self.into_document(), ())
}
}