diff --git a/src/nodes/node_dummy.rs b/src/nodes/node_dummy.rs index 5ee52a0ba69ac6395d0dd06c421b47087e7c7578..e5b03b849b898ef85fd4ba8e2cf47a34e7808e69 100644 --- a/src/nodes/node_dummy.rs +++ b/src/nodes/node_dummy.rs @@ -5,7 +5,7 @@ pub struct NodeDummy; impl Optical for NodeDummy { /// Returns "dummy" as node type. - fn node_type(&self) -> String { - "dummy".into() + fn node_type(&self) -> &str { + "dummy" } } \ No newline at end of file diff --git a/src/optic_node.rs b/src/optic_node.rs index 484eaf4d427adbbfbabc847641c721ad573481e8..4fbaa503fdb87614f3fe8ebaa027c3d6b76bf697 100644 --- a/src/optic_node.rs +++ b/src/optic_node.rs @@ -28,12 +28,13 @@ impl OpticNode { pub fn name(&self) -> &str { self.name.as_ref() } - /// Returns a string representation of the [`OpticNode`] in `graphviz` format. + /// Returns a string representation of the [`OpticNode`] in `graphviz` format. This function is normally called by the top-level `to_dot`function within + /// `OpticScenery`. pub fn to_dot(&self) -> String { format!(" \"{}\"\n", self.name) } /// Returns the concrete node type as string representation. - pub fn node_type(&self) -> String { + pub fn node_type(&self) -> &str { self.node.node_type() } } @@ -47,8 +48,8 @@ impl Debug for OpticNode { /// This trait must be implemented by all concrete optical components. pub trait Optical { /// Return the type of the optical component (lens, filter, ...). The default implementation returns "undefined". - fn node_type(&self) -> String { - "undefined".into() + fn node_type(&self) -> &str { + "undefined" } } @@ -77,4 +78,9 @@ mod test { let node = OpticNode::new("Test".into(), Box::new(NodeDummy)); assert_eq!(node.to_dot(), " \"Test\"\n".to_owned()) } + #[test] + fn node_type() { + let node = OpticNode::new("Test".into(), Box::new(NodeDummy)); + assert_eq!(node.node_type(), "dummy"); + } }