31 lines
619 B
Rust
31 lines
619 B
Rust
use std::{fmt, ops::Deref, rc::Rc};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub struct StringValue(Rc<str>);
|
|
|
|
impl From<&str> for StringValue {
|
|
fn from(value: &str) -> Self {
|
|
Self(value.into())
|
|
}
|
|
}
|
|
|
|
impl From<String> for StringValue {
|
|
fn from(value: String) -> Self {
|
|
Self(value.into())
|
|
}
|
|
}
|
|
|
|
impl Deref for StringValue {
|
|
type Target = str;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
self.0.as_ref()
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for StringValue {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
fmt::Display::fmt(self.0.as_ref(), f)
|
|
}
|
|
}
|