From 7762c7d41de89d9375abddba1b2439d86bad6e09 Mon Sep 17 00:00:00 2001 From: Udo Eisenbarth <u.eisenbarth@gsi.de> Date: Fri, 2 Jun 2023 10:58:45 +0200 Subject: [PATCH] Add node_type to Optical trait. --- src/nodes/node_dummy.rs | 7 +++++-- src/optic_node.rs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/nodes/node_dummy.rs b/src/nodes/node_dummy.rs index d71d07d1..5ee52a0b 100644 --- a/src/nodes/node_dummy.rs +++ b/src/nodes/node_dummy.rs @@ -1,8 +1,11 @@ use crate::optic_node::Optical; -/// A fake / dummy conponent without any functions. It is mainly used for development and debugging purposes. +/// A fake / dummy component without any functions. It is mainly used for development and debugging purposes. pub struct NodeDummy; impl Optical for NodeDummy { - + /// Returns "dummy" as node type. + fn node_type(&self) -> String { + "dummy".into() + } } \ No newline at end of file diff --git a/src/optic_node.rs b/src/optic_node.rs index 57cc26ba..484eaf4d 100644 --- a/src/optic_node.rs +++ b/src/optic_node.rs @@ -32,6 +32,10 @@ impl OpticNode { pub fn to_dot(&self) -> String { format!(" \"{}\"\n", self.name) } + /// Returns the concrete node type as string representation. + pub fn node_type(&self) -> String { + self.node.node_type() + } } impl Debug for OpticNode { @@ -39,7 +43,14 @@ impl Debug for OpticNode { write!(f, "{}", self.name) } } -pub trait Optical {} + +/// 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() + } +} #[cfg(test)] mod test { -- GitLab