use crate::ast::{CodeFormatter, Indentation, ParseScope, SimpleAttri};
use core::fmt::{self, Write};
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default)]
#[derive(serde::Serialize, serde::Deserialize)]
pub struct SdfExpression {
inner: String,
}
impl fmt::Display for SdfExpression {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.inner, f)
}
}
impl core::str::FromStr for SdfExpression {
type Err = core::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self { inner: String::from_str(s)? })
}
}
crate::ast::impl_self_builder!(SdfExpression);
impl SimpleAttri for SdfExpression {
#[inline]
fn nom_parse<'a>(
i: &'a str,
scope: &mut ParseScope,
) -> crate::ast::SimpleParseRes<'a, Self> {
crate::ast::nom_parse_from_str(i, scope)
}
#[inline]
fn fmt_self<T: Write, I: Indentation>(
&self,
f: &mut CodeFormatter<'_, T, I>,
) -> fmt::Result {
f.write_fmt(format_args!("\"{self}\""))
}
}
impl SdfExpression {
#[must_use]
#[inline]
pub const fn new(s: String) -> Self {
Self { inner: s }
}
}