calyx_utils/
pos_string.rsuse std::{fmt::Display, path::PathBuf};
use crate::{GPosIdx, WithPos};
#[derive(Clone, Debug, Default)]
pub struct PosString {
data: String,
span: GPosIdx,
}
impl From<String> for PosString {
fn from(data: String) -> PosString {
PosString {
data,
span: GPosIdx::UNKNOWN,
}
}
}
impl From<PosString> for String {
fn from(value: PosString) -> String {
value.data
}
}
impl From<PosString> for PathBuf {
fn from(value: PosString) -> Self {
value.data.into()
}
}
impl Display for PosString {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.data.fmt(f)
}
}
impl AsRef<str> for PosString {
fn as_ref(&self) -> &str {
&self.data
}
}
impl AsRef<std::path::Path> for PosString {
fn as_ref(&self) -> &std::path::Path {
self.data.as_ref()
}
}
impl WithPos for PosString {
fn copy_span(&self) -> GPosIdx {
self.span
}
}
impl PosString {
pub fn new(data: String, span: GPosIdx) -> Self {
Self { data, span }
}
pub fn with_span(mut self, span: GPosIdx) -> Self {
self.span = span;
self
}
}