Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Clarify when graph methods return None? #491

Merged
merged 1 commit into from May 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/graph_impl/mod.rs
Expand Up @@ -534,13 +534,15 @@ where

/// Access the weight for node `a`.
///
/// If node `a` doesn't exist in the graph, return `None`.
/// Also available with indexing syntax: `&graph[a]`.
pub fn node_weight(&self, a: NodeIndex<Ix>) -> Option<&N> {
self.nodes.get(a.index()).map(|n| &n.weight)
}

/// Access the weight for node `a`, mutably.
///
/// If node `a` doesn't exist in the graph, return `None`.
/// Also available with indexing syntax: `&mut graph[a]`.
pub fn node_weight_mut(&mut self, a: NodeIndex<Ix>) -> Option<&mut N> {
self.nodes.get_mut(a.index()).map(|n| &mut n.weight)
Expand Down Expand Up @@ -606,19 +608,23 @@ where

/// Access the weight for edge `e`.
///
/// If edge `e` doesn't exist in the graph, return `None`.
/// Also available with indexing syntax: `&graph[e]`.
pub fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E> {
self.edges.get(e.index()).map(|ed| &ed.weight)
}

/// Access the weight for edge `e`, mutably.
///
/// If edge `e` doesn't exist in the graph, return `None`.
/// Also available with indexing syntax: `&mut graph[e]`.
pub fn edge_weight_mut(&mut self, e: EdgeIndex<Ix>) -> Option<&mut E> {
self.edges.get_mut(e.index()).map(|ed| &mut ed.weight)
}

/// Access the source and target nodes for `e`.
///
/// If edge `e` doesn't exist in the graph, return `None`.
pub fn edge_endpoints(&self, e: EdgeIndex<Ix>) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)> {
self.edges
.get(e.index())
Expand Down