#[cfg(test)]
mod tests;
+use std::fmt::Display;
+
#[derive(Debug, Clone, PartialEq)]
pub enum Src {
Str(String),
}
impl Src {
- pub fn to_var(var: impl ToString) -> Self {
+ pub fn to_var(var: impl Display) -> Self {
Src::Var(var.to_string())
}
- pub fn to_arr(arr: impl ToString) -> Self {
+ pub fn to_arr(arr: impl Display) -> Self {
Src::Arr(arr.to_string())
}
- pub fn to_pat(pat: impl ToString) -> Self {
+ pub fn to_pat(pat: impl Display) -> Self {
Src::Pat(pat.to_string())
}
- pub fn to_str(str: impl ToString) -> Self {
+ pub fn to_str(str: impl Display) -> Self {
+ println!("{}", str.to_string());
Src::Str(str.to_string())
}
}
-impl ToString for Src {
- fn to_string(&self) -> String {
- match self {
+impl Display for Src {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let str = match self {
Src::Var(x) | Src::Arr(x) | Src::Pat(x) | Src::Str(x) => x.to_string(),
- }
+ };
+
+ write!(f, "{str}")
}
}
})?;
base.merge(self);
- base.patterns.insert(Scope::into_global("SOURCE"), html);
+ base.patterns.insert(Scope::create_global("SOURCE"), html);
let mut base_path = self.opts.pattern.join("base").join(
self.patterns
- .get(&Scope::into_global("base"))
+ .get(&Scope::create_global("base"))
.unwrap_or(&"default".into()),
);
let value = if let Some(val) = self.arrays.get(&name_key) {
&val[..]
- } else if let Some(val) = self.arrays.get(&name_key.to_global()) {
+ } else if let Some(val) = self.arrays.get(&name_key.global()) {
&val[..]
} else if let Some(val) = self.arrays.get(&class_key) {
&val[..]
- } else if let Some(val) = self.arrays.get(&class_key.to_global()) {
+ } else if let Some(val) = self.arrays.get(&class_key.global()) {
&val[..]
- } else if let Some(val) = self.arrays.get(&Scope::into_global(key)) {
+ } else if let Some(val) = self.arrays.get(&Scope::create_global(key)) {
&val[..]
- } else if let Some(val) = self.arrays.get(&Scope::into_local(key)) {
+ } else if let Some(val) = self.arrays.get(&Scope::create_local(key)) {
&val[..]
} else if self.opts.undefined {
panic!(
log!(self.opts, format!("expanding {key}"), 2);
// SOURCE is already expanded in the initial construct() call
if key == "SOURCE" {
- if let Some(source) = self.patterns.get(&Scope::into_global("SOURCE")) {
+ if let Some(source) = self.patterns.get(&Scope::create_global("SOURCE")) {
return Ok(source.to_string());
} else {
return Ok(String::new());
}
}
- let mut filename = if let Some(name) = self.patterns.get(&Scope::into_local(key)) {
+ let mut filename = if let Some(name) = self.patterns.get(&Scope::create_local(key)) {
Ok(name.to_string())
- } else if let Some(name) = self.patterns.get(&Scope::into_global(key)) {
+ } else if let Some(name) = self.patterns.get(&Scope::create_global(key)) {
Ok(name.to_string())
} else if self
.opts
+use std::fmt::Display;
+
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
pub enum Scope {
Local(String),
}
impl Scope {
- pub fn into_local(str: impl ToString) -> Scope {
+ pub fn create_local(str: impl Display) -> Scope {
Scope::Local(str.to_string())
}
- pub fn into_global(str: impl ToString) -> Scope {
+ pub fn create_global(str: impl ToString) -> Scope {
Scope::Global(str.to_string())
}
}
}
- pub fn to_local(&self) -> Scope {
+ pub fn local(&self) -> Scope {
Scope::Local(self.to_string())
}
- pub fn to_global(&self) -> Scope {
+ pub fn global(&self) -> Scope {
Scope::Global(self.to_string())
}
}
-impl ToString for Scope {
- fn to_string(&self) -> String {
- match self {
+impl Display for Scope {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let str = match self {
Scope::Local(x) | Scope::Global(x) => x.to_string(),
- }
+ };
+
+ write!(f, "{str}")
}
}
}
if global {
- Ok((Scope::into_global(key), val))
+ Ok((Scope::create_global(key), val))
} else {
- Ok((Scope::into_local(key), val))
+ Ok((Scope::create_local(key), val))
}
}
}
if global {
- Ok((Scope::into_global(key), val))
+ Ok((Scope::create_global(key), val))
} else {
- Ok((Scope::into_local(key), val))
+ Ok((Scope::create_local(key), val))
}
}