use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ChildName {
segments: Vec<String>,
}
impl ChildName {
pub fn from_segments<I, S>(segments: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
segments: segments.into_iter().map(Into::into).collect(),
}
}
pub fn phase(name: impl Into<String>) -> Self {
Self {
segments: vec!["phase".into(), name.into()],
}
}
pub fn op(name: impl Into<String>) -> Self {
Self {
segments: vec!["op".into(), name.into()],
}
}
pub fn iteration(coord: impl Into<String>) -> Self {
Self {
segments: vec!["iter".into(), coord.into()],
}
}
pub fn compose(parent_name: &ChildName, segment: impl Into<String>) -> Self {
let mut segments = parent_name.segments.clone();
segments.push(segment.into());
Self { segments }
}
pub fn segments(&self) -> &[String] {
&self.segments
}
pub fn display(&self) -> String {
self.segments.join("/")
}
}
impl fmt::Display for ChildName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.display())
}
}