Allow setting value of a node without touching its connections.
This commit is contained in:
parent
9873b6bd52
commit
b078e13cb6
10
src/lib.rs
10
src/lib.rs
|
|
@ -51,6 +51,16 @@ impl<NodeValueT: NodeValue> Graph<NodeValueT> {
|
|||
Ok(new_node_key)
|
||||
}
|
||||
|
||||
/// Replace the value of `key` with value `value`.
|
||||
/// `key` must already exist in the graph, and no connections will be modified.
|
||||
pub fn replace_value_of(&mut self, key: &Key, value: NodeValueT) -> Result<(), GraphError> {
|
||||
if let Some(node) = self.nodes.get_mut(*key) {
|
||||
node.set_value(value);
|
||||
return Ok(());
|
||||
}
|
||||
return Err(GraphError::from_msg("Can't set value of invalid key."));
|
||||
}
|
||||
|
||||
/// Get the value of key `key` if the key is valid.
|
||||
pub fn value_of(&self, key: &Key) -> Result<NodeValueT, GraphError> {
|
||||
if key >= &self.nodes.len() {
|
||||
|
|
|
|||
|
|
@ -46,4 +46,8 @@ impl<NodeValueT: NodeValue> Node<NodeValueT> {
|
|||
pub fn value(&self) -> NodeValueT {
|
||||
self.value.clone()
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, value: NodeValueT) {
|
||||
self.value = value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue