Trait Categorized

Source
pub trait Categorized<N, E, C>: GraphInterface<NodeData = N, EdgeData = E> {
Show 14 methods // Required methods fn category_id_by_name(&self, category_name: &str) -> Option<&NodeID>; fn create_category( &mut self, category: &str, nodes: Vec<NodeID>, data: C, ) -> Result<NodeID, String> where E: Default + Clone, N: Clone + Default; fn all_categories(&self) -> Vec<(&String, NodeID)>; fn category(&self, category: &str) -> Option<&Node<N>>; fn category_by_id(&self, category: NodeID) -> Result<&Node<N>, GraphError>; fn nodes_by_category_id(&self, category: NodeID) -> Vec<NodeID>; fn nodes_by_category(&self, category: &str) -> Vec<NodeID>; // Provided methods fn category_exists(&self, category_name: &str) -> bool { ... } fn add_to_category_by_id( &mut self, category_id: NodeID, nodes: Vec<NodeID>, ) -> Result<(), CategorizedGraphError> where E: Default + Clone, N: Clone { ... } fn insert_category_id_by_name( &mut self, category_name: &str, category_id: NodeID, ) { ... } fn add_to_category( &mut self, category_name: &str, nodes: Vec<NodeID>, ) -> NodeID where E: Default + Clone, N: Clone + Default { ... } fn category_exists_by_id(&self, category: NodeID) -> bool { ... } fn nodes_by_categories(&self, categories: Vec<&str>) -> Vec<NodeID> { ... } fn nodes_by_category_ids(&self, categories: Vec<NodeID>) -> Vec<NodeID> { ... }
}
Expand description

Methods for a graph with categories.

Required Methods§

Source

fn category_id_by_name(&self, category_name: &str) -> Option<&NodeID>

Returns the category ID by name. In the standard implementation this is a hashmap lookup.

Source

fn create_category( &mut self, category: &str, nodes: Vec<NodeID>, data: C, ) -> Result<NodeID, String>
where E: Default + Clone, N: Clone + Default,

Creates a new category Node with the given name, nodes, and (optionally) data.

Returns the NodeID of the category if successful, otherwise returns Error(CategorizedGraphError::CategoryAlreadyExists).

An empty vector of nodes can be passed.

Source

fn all_categories(&self) -> Vec<(&String, NodeID)>

Returns a list of all categories.

Source

fn category(&self, category: &str) -> Option<&Node<N>>

Returns the category node by name.

Source

fn category_by_id(&self, category: NodeID) -> Result<&Node<N>, GraphError>

Returns the category node by ID.

Source

fn nodes_by_category_id(&self, category: NodeID) -> Vec<NodeID>

Returns a list of nodes in the category by ID.

Source

fn nodes_by_category(&self, category: &str) -> Vec<NodeID>

Returns a list of nodes in the category by name.

Provided Methods§

Source

fn category_exists(&self, category_name: &str) -> bool

Checks if the category exists by name.

Source

fn add_to_category_by_id( &mut self, category_id: NodeID, nodes: Vec<NodeID>, ) -> Result<(), CategorizedGraphError>
where E: Default + Clone, N: Clone,

Adds a list of nodes to a category by ID. Returns Ok(()) if successful, otherwise returns Error(CategorizedGraphError::CategoryNotFound).

Source

fn insert_category_id_by_name( &mut self, category_name: &str, category_id: NodeID, )

In the default implementation this is used to insert the category ID into the hashmap.

Source

fn add_to_category(&mut self, category_name: &str, nodes: Vec<NodeID>) -> NodeID
where E: Default + Clone, N: Clone + Default,

If the category does not exist, it is created. Returns the NodeID of the category.

Source

fn category_exists_by_id(&self, category: NodeID) -> bool

Checks if the category exists by ID.

Source

fn nodes_by_categories(&self, categories: Vec<&str>) -> Vec<NodeID>

Returns a list of nodes in the categories by name.

Source

fn nodes_by_category_ids(&self, categories: Vec<NodeID>) -> Vec<NodeID>

Returns a list of nodes in the categories by ID.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<N, E> Categorized<N, E, N> for CategorizedGraph<N, E>
where Self: GraphInterface<NodeData = N, EdgeData = E>,