Merge pull request #275 from ultrasaurus/node_indices-doc
inline doc example for node_indices
diff --git a/.travis.yml b/.travis.yml
index 720573c..f32ebc8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@
sudo: false
matrix:
include:
- - rust: 1.25.0
+ - rust: 1.37.0
env:
- ALL=' '
- rust: stable
diff --git a/Cargo.toml b/Cargo.toml
index ca207ec..1221614 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,11 +10,13 @@
description = "Graph data structure library. Provides graph types and graph algorithms."
documentation = "https://docs.rs/petgraph/"
-repository = "https://github.com/bluss/petgraph"
+repository = "https://github.com/petgraph/petgraph"
keywords = ["data-structure", "graph", "unionfind", "graph-algorithms"]
categories = ["data-structures"]
+edition = "2018"
+
[lib]
name = "petgraph"
@@ -27,7 +29,7 @@
[dependencies]
fixedbitset = { version = "0.1.4" }
-quickcheck = { optional = true, version = "0.7.1", default-features = false }
+quickcheck = { optional = true, version = "0.8", default-features = false }
indexmap = { version = "1.0.2", optional = true }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
diff --git a/README.rst b/README.rst
index 0243d46..ffe1b7a 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@
petgraph
========
-Graph data structure library. Requires Rust 1.25 or later.
+Graph data structure library. Known to support Rust 1.37 and later.
Please read the `API documentation here`__
diff --git a/benches/stable_graph.rs b/benches/stable_graph.rs
index 9bbda8f..d5a1e18 100644
--- a/benches/stable_graph.rs
+++ b/benches/stable_graph.rs
@@ -195,12 +195,12 @@
fn stable_graph_retain_nodes(bench: &mut Bencher)
{
let mut a = parse_stable_graph::<Directed>(BIGGER);
- bench.iter(|| a.retain_nodes(|gr, i| (i.index() + 1) % 3700 != 0));
+ bench.iter(|| a.retain_nodes(|_gr, i| (i.index() + 1) % 3700 != 0));
}
#[bench]
fn stable_graph_retain_edges(bench: &mut Bencher)
{
let mut a = parse_stable_graph::<Directed>(BIGGER);
- bench.iter(|| a.retain_edges(|gr, i| (i.index() + 1) % 3700 != 0));
+ bench.iter(|| a.retain_edges(|_gr, i| (i.index() + 1) % 3700 != 0));
}
diff --git a/serialization-tests/Cargo.toml b/serialization-tests/Cargo.toml
index 063fd44..6ac6e58 100644
--- a/serialization-tests/Cargo.toml
+++ b/serialization-tests/Cargo.toml
@@ -19,6 +19,6 @@
[dev-dependencies]
serde_json = "1.0"
-quickcheck = { version = "0.7.1", default-features = false }
+quickcheck = { version = "0.8", default-features = false }
bincode = "1.0.1"
defmac = "0.1"
diff --git a/src/algo/dominators.rs b/src/algo/dominators.rs
index fd41140..e6b22f4 100644
--- a/src/algo/dominators.rs
+++ b/src/algo/dominators.rs
@@ -15,7 +15,7 @@
use std::collections::{HashMap, HashSet};
use std::hash::Hash;
-use visit::{DfsPostOrder, GraphBase, IntoNeighbors, Visitable, Walker};
+use crate::visit::{DfsPostOrder, GraphBase, IntoNeighbors, Visitable, Walker};
/// The dominance relation for some graph and root.
#[derive(Debug, Clone)]
diff --git a/src/algo/mod.rs b/src/algo/mod.rs
index b64f536..2d3087f 100644
--- a/src/algo/mod.rs
+++ b/src/algo/mod.rs
@@ -9,12 +9,12 @@
use std::collections::BinaryHeap;
use std::cmp::min;
-use prelude::*;
+use crate::prelude::*;
use super::{
EdgeType,
};
-use scored::MinScored;
+use crate::scored::MinScored;
use super::visit::{
GraphRef,
GraphBase,
@@ -34,9 +34,9 @@
use super::graph::{
IndexType,
};
-use visit::{Data, NodeRef, IntoNodeReferences};
-use visit::Walker;
-use data::{
+use crate::visit::{Data, NodeRef, IntoNodeReferences};
+use crate::visit::Walker;
+use crate::data::{
Element,
};
@@ -47,7 +47,7 @@
pub use super::dijkstra::dijkstra;
pub use super::astar::astar;
-/// [Generic] Return the number of connected components of the graph.
+/// \[Generic\] Return the number of connected components of the graph.
///
/// For a directed graph, this is the *weakly* connected components.
/// # Example
@@ -102,7 +102,7 @@
}
-/// [Generic] Return `true` if the input graph contains a cycle.
+/// \[Generic\] Return `true` if the input graph contains a cycle.
///
/// Always treats the input graph as if undirected.
pub fn is_cyclic_undirected<G>(g: G) -> bool
@@ -122,7 +122,7 @@
}
-/// [Generic] Perform a topological sort of a directed graph.
+/// \[Generic\] Perform a topological sort of a directed graph.
///
/// If the graph was acyclic, return a vector of nodes in topological order:
/// each node is ordered before its successors.
@@ -187,14 +187,14 @@
})
}
-/// [Generic] Return `true` if the input directed graph contains a cycle.
+/// \[Generic\] Return `true` if the input directed graph contains a cycle.
///
/// This implementation is recursive; use `toposort` if an alternative is
/// needed.
pub fn is_cyclic_directed<G>(g: G) -> bool
where G: IntoNodeIdentifiers + IntoNeighbors + Visitable,
{
- use visit::{depth_first_search, DfsEvent};
+ use crate::visit::{depth_first_search, DfsEvent};
depth_first_search(g, g.node_identifiers(), |event| {
match event {
@@ -251,7 +251,7 @@
f(dfs)
}
-/// [Generic] Check if there exists a path starting at `from` and reaching `to`.
+/// \[Generic\] Check if there exists a path starting at `from` and reaching `to`.
///
/// If `from` and `to` are equal, this function returns true.
///
@@ -277,7 +277,7 @@
kosaraju_scc(g)
}
-/// [Generic] Compute the *strongly connected components* using [Kosaraju's algorithm][1].
+/// \[Generic\] Compute the *strongly connected components* using [Kosaraju's algorithm][1].
///
/// [1]: https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm
///
@@ -328,7 +328,7 @@
sccs
}
-/// [Generic] Compute the *strongly connected components* using [Tarjan's algorithm][1].
+/// \[Generic\] Compute the *strongly connected components* using [Tarjan's algorithm][1].
///
/// [1]: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
///
@@ -544,7 +544,7 @@
condensed
}
-/// [Generic] Compute a *minimum spanning tree* of a graph.
+/// \[Generic\] Compute a *minimum spanning tree* of a graph.
///
/// The input graph is treated as if undirected.
///
@@ -647,7 +647,7 @@
#[derive(Clone, Debug, PartialEq)]
pub struct NegativeCycle(());
-/// [Generic] Compute shortest paths from node `source` to all other.
+/// \[Generic\] Compute shortest paths from node `source` to all other.
///
/// Using the [Bellman–Ford algorithm][bf]; negative edge costs are
/// permitted, but the graph must not have a cycle of negative weights
diff --git a/src/astar.rs b/src/astar.rs
index 0ebd4fe..b9435f5 100644
--- a/src/astar.rs
+++ b/src/astar.rs
@@ -9,7 +9,7 @@
use std::hash::Hash;
-use scored::MinScored;
+use crate::scored::MinScored;
use super::visit::{
EdgeRef,
GraphBase,
@@ -18,9 +18,9 @@
Visitable,
};
-use algo::Measure;
+use crate::algo::Measure;
-/// [Generic] A* shortest path algorithm.
+/// \[Generic\] A* shortest path algorithm.
///
/// Computes the shortest path from `start` to `finish`, including the total path cost.
///
diff --git a/src/csr.rs b/src/csr.rs
index 1ce87cc..7c603f5 100644
--- a/src/csr.rs
+++ b/src/csr.rs
@@ -6,16 +6,16 @@
use std::iter::{Enumerate, Zip};
use std::slice::Windows;
-use visit::{EdgeRef, GraphBase, IntoNeighbors, NodeIndexable, IntoEdges};
-use visit::{NodeCompactIndexable, IntoNodeIdentifiers, Visitable};
-use visit::{Data, IntoEdgeReferences, NodeCount, GraphProp};
+use crate::visit::{EdgeRef, GraphBase, IntoNeighbors, NodeIndexable, IntoEdges};
+use crate::visit::{NodeCompactIndexable, IntoNodeIdentifiers, Visitable};
+use crate::visit::{Data, IntoEdgeReferences, NodeCount, GraphProp};
-use util::zip;
+use crate::util::zip;
#[doc(no_inline)]
-pub use graph::{IndexType, DefaultIx};
+pub use crate::graph::{IndexType, DefaultIx};
-use {
+use crate::{
EdgeType,
Directed,
IntoWeightedEdge,
@@ -43,6 +43,7 @@
/// Self loops are allowed, no parallel edges.
///
/// Fast iteration of the outgoing edges of a vertex.
+///
/// [`CSR`]: https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_(CSR,_CRS_or_Yale_format)
#[derive(Debug)]
pub struct Csr<N = (), E = (), Ty = Directed, Ix = DefaultIx> {
@@ -269,7 +270,7 @@
/// Adds a new node with the given weight, returning the corresponding node index.
pub fn add_node(&mut self, weight: N) -> NodeIndex<Ix> {
let i = self.row.len() - 1;
- self.row.insert(i, 0);
+ self.row.insert(i, self.column.len());
self.node_weights.insert(i, weight);
Ix::new(i)
}
@@ -701,11 +702,11 @@
#[cfg(test)]
mod tests {
use super::Csr;
- use Undirected;
- use visit::Dfs;
- use visit::VisitMap;
- use algo::tarjan_scc;
- use algo::bellman_ford;
+ use crate::Undirected;
+ use crate::visit::Dfs;
+ use crate::visit::VisitMap;
+ use crate::algo::tarjan_scc;
+ use crate::algo::bellman_ford;
#[test]
fn csr1() {
@@ -889,8 +890,8 @@
#[test]
fn test_edge_references() {
- use visit::EdgeRef;
- use visit::IntoEdgeReferences;
+ use crate::visit::EdgeRef;
+ use crate::visit::IntoEdgeReferences;
let m: Csr<(), _> = Csr::from_sorted_edges(&[
(0, 1, 0.5),
(0, 2, 2.),
@@ -937,4 +938,25 @@
assert_eq!(g.edge_count(), 3);
}
+
+ #[test]
+ fn test_add_node_with_existing_edges() {
+ let mut g: Csr = Csr::new();
+ let a = g.add_node(());
+ let b = g.add_node(());
+
+ assert!(g.add_edge(a, b, ()));
+
+ let c = g.add_node(());
+
+ println!("{:?}", g);
+
+ assert_eq!(g.node_count(), 3);
+
+ assert_eq!(g.neighbors_slice(a), &[b]);
+ assert_eq!(g.neighbors_slice(b), &[]);
+ assert_eq!(g.neighbors_slice(c), &[]);
+
+ assert_eq!(g.edge_count(), 1);
+ }
}
diff --git a/src/data.rs b/src/data.rs
index 1509461..03f1b31 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -1,16 +1,16 @@
//! Graph traits for associated data and graph construction.
-use Graph;
+use crate::Graph;
#[cfg(feature = "stable_graph")]
-use stable_graph::StableGraph;
-use ::{
+use crate::stable_graph::StableGraph;
+use crate::{
EdgeType,
};
-use graph::IndexType;
+use crate::graph::IndexType;
#[cfg(feature = "graphmap")]
-use graphmap::{GraphMap, NodeTrait};
-use visit::{
+use crate::graphmap::{GraphMap, NodeTrait};
+use crate::visit::{
Data,
NodeCount,
NodeIndexable,
diff --git a/src/dijkstra.rs b/src/dijkstra.rs
index e7b6feb..b856e60 100644
--- a/src/dijkstra.rs
+++ b/src/dijkstra.rs
@@ -9,16 +9,16 @@
use std::hash::Hash;
-use scored::MinScored;
+use crate::scored::MinScored;
use super::visit::{
Visitable,
VisitMap,
IntoEdges,
EdgeRef,
};
-use algo::Measure;
+use crate::algo::Measure;
-/// [Generic] Dijkstra's shortest path algorithm.
+/// \[Generic\] Dijkstra's shortest path algorithm.
///
/// Compute the length of the shortest path from `start` to every reachable
/// node.
diff --git a/src/dot.rs b/src/dot.rs
index 09bf26b..7defdee 100644
--- a/src/dot.rs
+++ b/src/dot.rs
@@ -2,7 +2,7 @@
use std::fmt::{self, Display, Write};
-use visit::{GraphRef};
+use crate::visit::{GraphRef};
/// `Dot` implements output to graphviz .dot format for a graph.
///
@@ -80,12 +80,14 @@
EdgeIndexLabel,
/// Use no edge labels.
EdgeNoLabel,
+ /// Do not print the graph/digraph string.
+ GraphContentOnly,
#[doc(hidden)]
_Incomplete(()),
}
-use visit::{ IntoNodeReferences, NodeIndexable, IntoEdgeReferences, EdgeRef};
-use visit::{ Data, NodeRef, GraphProp, };
+use crate::visit::{ IntoNodeReferences, NodeIndexable, IntoEdgeReferences, EdgeRef};
+use crate::visit::{ Data, NodeRef, GraphProp, };
impl<'a, G> Dot<'a, G>
{
@@ -94,42 +96,46 @@
where G: NodeIndexable + IntoNodeReferences + IntoEdgeReferences,
G: GraphProp,
G: Data<NodeWeight=NW, EdgeWeight=EW>,
- NF: FnMut(&NW, &mut FnMut(&Display) -> fmt::Result) -> fmt::Result,
- EF: FnMut(&EW, &mut FnMut(&Display) -> fmt::Result) -> fmt::Result,
+ NF: FnMut(&NW, &mut dyn FnMut(&dyn Display) -> fmt::Result) -> fmt::Result,
+ EF: FnMut(&EW, &mut dyn FnMut(&dyn Display) -> fmt::Result) -> fmt::Result,
{
- try!(writeln!(f, "{} {{", TYPE[g.is_directed() as usize]));
+ if !self.config.contains(&Config::GraphContentOnly) {
+ writeln!(f, "{} {{", TYPE[g.is_directed() as usize])?;
+ }
// output all labels
for node in g.node_references() {
- try!(write!(f, "{}{}", INDENT, g.to_index(node.id())));
+ write!(f, "{}{}", INDENT, g.to_index(node.id()))?;
if self.config.contains(&Config::NodeIndexLabel) {
- try!(writeln!(f, ""));
+ writeln!(f)?;
} else {
- try!(write!(f, " [label=\""));
- try!(node_fmt(node.weight(), &mut |d| Escaped(d).fmt(f)));
- try!(writeln!(f, "\"]"));
+ write!(f, " [label=\"")?;
+ node_fmt(node.weight(), &mut |d| Escaped(d).fmt(f))?;
+ writeln!(f, "\"]")?;
}
}
// output all edges
for (i, edge) in g.edge_references().enumerate() {
- try!(write!(f, "{}{} {} {}",
+ write!(f, "{}{} {} {}",
INDENT,
g.to_index(edge.source()),
EDGE[g.is_directed() as usize],
- g.to_index(edge.target())));
+ g.to_index(edge.target()))?;
if self.config.contains(&Config::EdgeNoLabel) {
- try!(writeln!(f, ""));
+ writeln!(f)?;
} else if self.config.contains(&Config::EdgeIndexLabel) {
- try!(writeln!(f, " [label=\"{}\"]", i));
+ writeln!(f, " [label=\"{}\"]", i)?;
} else {
- try!(write!(f, " [label=\""));
- try!(edge_fmt(edge.weight(), &mut |d| Escaped(d).fmt(f)));
- try!(writeln!(f, "\"]"));
+ write!(f, " [label=\"")?;
+ edge_fmt(edge.weight(), &mut |d| Escaped(d).fmt(f))?;
+ writeln!(f, "\"]")?;
}
}
- try!(writeln!(f, "}}"));
+ if !self.config.contains(&Config::GraphContentOnly) {
+ writeln!(f, "}}")?;
+ }
Ok(())
}
}
@@ -164,14 +170,14 @@
{
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() {
- try!(self.write_char(c));
+ self.write_char(c)?;
}
Ok(())
}
fn write_char(&mut self, c: char) -> fmt::Result {
match c {
- '"' | '\\' => try!(self.0.write_char('\\')),
+ '"' | '\\' => self.0.write_char('\\')?,
// \l is for left justified linebreak
'\n' => return self.0.write_str("\\l"),
_ => {}
@@ -188,7 +194,7 @@
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if f.alternate() {
- write!(&mut Escaper(f), "{:#}\n", &self.0)
+ writeln!(&mut Escaper(f), "{:#}", &self.0)
} else {
write!(&mut Escaper(f), "{}", &self.0)
}
diff --git a/src/generate.rs b/src/generate.rs
index 91ea64a..e717239 100644
--- a/src/generate.rs
+++ b/src/generate.rs
@@ -3,8 +3,8 @@
//! ***Unstable: API may change at any time.*** Depends on `feature = "generate"`.
//!
-use {Graph, Directed, EdgeType};
-use graph::NodeIndex;
+use crate::{Graph, Directed, EdgeType};
+use crate::graph::NodeIndex;
// A DAG has the property that the adjacency matrix is lower triangular,
// diagonal zero.
diff --git a/src/graph_impl/frozen.rs b/src/graph_impl/frozen.rs
index 488cc55..bb96618 100644
--- a/src/graph_impl/frozen.rs
+++ b/src/graph_impl/frozen.rs
@@ -1,17 +1,17 @@
use std::ops::{Deref, Index, IndexMut};
-use graph::Graph;
+use crate::graph::Graph;
use super::Frozen;
-use graph::{IndexType, GraphIndex};
-use {
+use crate::graph::{IndexType, GraphIndex};
+use crate::{
Direction,
EdgeType,
};
-use visit::{Data, IntoNodeIdentifiers, GraphProp, NodeIndexable, IntoNeighborsDirected};
-use visit::{IntoNeighbors, IntoNodeReferences, IntoEdgeReferences, Visitable};
-use visit::{NodeCompactIndexable, GetAdjacencyMatrix, NodeCount, IntoEdges, IntoEdgesDirected};
-use data::{DataMap, DataMapMut};
+use crate::visit::{Data, IntoNodeIdentifiers, GraphProp, NodeIndexable, IntoNeighborsDirected};
+use crate::visit::{IntoNeighbors, IntoNodeReferences, IntoEdgeReferences, Visitable};
+use crate::visit::{NodeCompactIndexable, GetAdjacencyMatrix, NodeCount, IntoEdges, IntoEdgesDirected};
+use crate::data::{DataMap, DataMapMut};
impl<'a, G> Frozen<'a, G> {
diff --git a/src/graph_impl/mod.rs b/src/graph_impl/mod.rs
index 383abf5..91eea58 100644
--- a/src/graph_impl/mod.rs
+++ b/src/graph_impl/mod.rs
@@ -7,7 +7,7 @@
use std::ops::{Index, IndexMut, Range};
use std::slice;
-use {
+use crate::{
Direction, Outgoing, Incoming,
Undirected,
Directed,
@@ -15,15 +15,15 @@
IntoWeightedEdge,
};
-use iter_format::{
+use crate::iter_format::{
IterFormatExt,
NoPretty,
DebugMap,
};
-use visit::EdgeRef;
-use visit::{IntoNodeReferences, IntoEdges, IntoEdgesDirected};
-use util::enumerate;
+use crate::visit::EdgeRef;
+use crate::visit::{IntoNodeReferences, IntoEdges, IntoEdgesDirected};
+use crate::util::enumerate;
#[cfg(feature = "serde-1")]
mod serialization;
@@ -1546,7 +1546,7 @@
edges: &'a [Edge<E, Ix>],
/// Next edge to visit.
- /// If we are only following one direction, we only use next[0] regardless.
+ /// If we are only following one direction, we only use `next[0]` regardless.
next: [EdgeIndex<Ix>; 2],
/// Which direction to follow
diff --git a/src/graph_impl/serialization.rs b/src/graph_impl/serialization.rs
index c400693..8c93c2e 100644
--- a/src/graph_impl/serialization.rs
+++ b/src/graph_impl/serialization.rs
@@ -3,14 +3,14 @@
use std::marker::PhantomData;
-use prelude::*;
+use crate::prelude::*;
-use EdgeType;
-use graph::Node;
-use graph::{IndexType, Edge};
-use serde_utils::MappedSequenceVisitor;
-use serde_utils::CollectSeqWithLength;
-use serde_utils::{IntoSerializable, FromDeserialized};
+use crate::EdgeType;
+use crate::graph::Node;
+use crate::graph::{IndexType, Edge};
+use crate::serde_utils::MappedSequenceVisitor;
+use crate::serde_utils::CollectSeqWithLength;
+use crate::serde_utils::{IntoSerializable, FromDeserialized};
use super::{NodeIndex, EdgeIndex};
use serde::{Serialize, Serializer, Deserialize, Deserializer};
diff --git a/src/graph_impl/stable_graph/mod.rs b/src/graph_impl/stable_graph/mod.rs
index 293efaa..c730336 100644
--- a/src/graph_impl/stable_graph/mod.rs
+++ b/src/graph_impl/stable_graph/mod.rs
@@ -12,7 +12,7 @@
use std::ops::{Index, IndexMut};
use std::slice;
-use {
+use crate::{
Graph,
EdgeType,
Directed,
@@ -22,12 +22,12 @@
Outgoing,
};
-use iter_format::{
+use crate::iter_format::{
IterFormatExt,
NoPretty,
DebugMap,
};
-use iter_utils::IterUtilsExt;
+use crate::iter_utils::IterUtilsExt;
use super::{
Edge,
@@ -37,8 +37,8 @@
Pair,
Frozen,
};
-use IntoWeightedEdge;
-use visit::{
+use crate::IntoWeightedEdge;
+use crate::visit::{
EdgeRef,
IntoNodeReferences,
IntoEdges,
@@ -49,7 +49,7 @@
// reexport those things that are shared with Graph
#[doc(no_inline)]
-pub use graph::{
+pub use crate::graph::{
NodeIndex,
EdgeIndex,
GraphIndex,
@@ -59,7 +59,7 @@
edge_index,
};
-use util::enumerate;
+use crate::util::enumerate;
#[cfg(feature = "serde-1")]
mod serialization;
@@ -1291,7 +1291,7 @@
edges: &'a [Edge<Option<E>, Ix>],
/// Next edge to visit.
- /// If we are only following one direction, we only use next[0] regardless.
+ /// If we are only following one direction, we only use `next[0]` regardless.
next: [EdgeIndex<Ix>; 2],
/// Which direction to follow
@@ -1682,7 +1682,7 @@
#[test]
fn dfs() {
- use visit::Dfs;
+ use crate::visit::Dfs;
let mut gr = StableGraph::<_, _>::with_capacity(0, 0);
let a = gr.add_node("a");
diff --git a/src/graph_impl/stable_graph/serialization.rs b/src/graph_impl/stable_graph/serialization.rs
index bc26c57..da031c6 100644
--- a/src/graph_impl/stable_graph/serialization.rs
+++ b/src/graph_impl/stable_graph/serialization.rs
@@ -5,17 +5,17 @@
use std::marker::PhantomData;
-use prelude::*;
+use crate::prelude::*;
-use EdgeType;
-use graph::Node;
-use graph::{IndexType, Edge};
-use stable_graph::StableGraph;
-use util::rev;
-use serde_utils::MappedSequenceVisitor;
-use serde_utils::CollectSeqWithLength;
-use serde_utils::{IntoSerializable, FromDeserialized};
-use visit::NodeIndexable;
+use crate::EdgeType;
+use crate::graph::Node;
+use crate::graph::{IndexType, Edge};
+use crate::stable_graph::StableGraph;
+use crate::util::rev;
+use crate::serde_utils::MappedSequenceVisitor;
+use crate::serde_utils::CollectSeqWithLength;
+use crate::serde_utils::{IntoSerializable, FromDeserialized};
+use crate::visit::NodeIndexable;
use super::super::serialization::{EdgeProperty, invalid_length_err, invalid_node_err};
@@ -231,8 +231,8 @@
#[test]
fn test_from_deserialized_with_holes() {
- use graph::node_index;
- use stable_graph::StableUnGraph;
+ use crate::graph::node_index;
+ use crate::stable_graph::StableUnGraph;
use serde::de::value::Error as SerdeError;
use itertools::assert_equal;
diff --git a/src/graphmap.rs b/src/graphmap.rs
index 5adac89..8a4d97c 100644
--- a/src/graphmap.rs
+++ b/src/graphmap.rs
@@ -20,7 +20,7 @@
};
use indexmap::map::Keys;
-use {
+use crate::{
EdgeType,
Directed,
Undirected,
@@ -29,11 +29,11 @@
Outgoing,
};
-use IntoWeightedEdge;
-use visit::{IntoNodeIdentifiers, NodeCount, IntoNodeReferences, NodeIndexable};
-use visit::{NodeCompactIndexable, IntoEdgeReferences, IntoEdges};
-use graph::Graph;
-use graph::node_index;
+use crate::IntoWeightedEdge;
+use crate::visit::{IntoNodeIdentifiers, NodeCount, IntoNodeReferences, NodeIndexable};
+use crate::visit::{NodeCompactIndexable, IntoEdgeReferences, IntoEdges};
+use crate::graph::Graph;
+use crate::graph::node_index;
/// A `GraphMap` with undirected edges.
///
@@ -414,7 +414,7 @@
/// **Panics** if the number of nodes or edges does not fit with
/// the resulting graph's index type.
pub fn into_graph<Ix>(self) -> Graph<N, E, Ty, Ix>
- where Ix: ::graph::IndexType,
+ where Ix: crate::graph::IndexType,
{
// assuming two successive iterations of the same hashmap produce the same order
let mut gr = Graph::with_capacity(self.node_count(), self.edge_count());
diff --git a/src/isomorphism.rs b/src/isomorphism.rs
index 8632dde..1554b37 100644
--- a/src/isomorphism.rs
+++ b/src/isomorphism.rs
@@ -201,7 +201,7 @@
trait SemanticMatcher<T> {
fn enabled() -> bool;
- fn eq(&mut self, &T, &T) -> bool;
+ fn eq(&mut self, _: &T, _: &T) -> bool;
}
struct NoSemanticMatch;
diff --git a/src/iter_format.rs b/src/iter_format.rs
index 3f1c9cf..de03a2a 100644
--- a/src/iter_format.rs
+++ b/src/iter_format.rs
@@ -70,12 +70,12 @@
};
if let Some(fst) = iter.next() {
- try!(cb(&fst, f));
+ cb(&fst, f)?;
for elt in iter {
if !self.sep.is_empty() {
- try!(f.write_str(self.sep));
+ f.write_str(self.sep)?;
}
- try!(cb(&elt, f));
+ cb(&elt, f)?;
}
}
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 7c6f82a..5febc29 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -31,9 +31,9 @@
extern crate itertools;
#[doc(no_inline)]
-pub use graph::Graph;
+pub use crate::graph::Graph;
-pub use Direction::{Outgoing, Incoming};
+pub use crate::Direction::{Outgoing, Incoming};
#[macro_use]
mod macros;
@@ -70,7 +70,7 @@
/// `Graph<N, E, Ty, Ix>` is a graph datastructure using an adjacency list representation.
pub mod graph {
- pub use graph_impl::{
+ pub use crate::graph_impl::{
Edge,
EdgeIndex,
EdgeIndices,
@@ -99,7 +99,7 @@
}
#[cfg(feature = "stable_graph")]
-pub use graph_impl::stable_graph;
+pub use crate::graph_impl::stable_graph;
macro_rules! copyclone {
($name:ident) => {
@@ -141,7 +141,7 @@
}
#[doc(hidden)]
-pub use Direction as EdgeDirection;
+pub use crate::Direction as EdgeDirection;
/// Marker type for a directed graph.
#[derive(Copy, Debug)]
diff --git a/src/prelude.rs b/src/prelude.rs
index 51602c9..d35161e 100644
--- a/src/prelude.rs
+++ b/src/prelude.rs
@@ -6,7 +6,7 @@
//! ```
#[doc(no_inline)]
-pub use graph::{
+pub use crate::graph::{
Graph,
NodeIndex,
EdgeIndex,
@@ -15,26 +15,26 @@
};
#[cfg(feature = "graphmap")]
#[doc(no_inline)]
-pub use graphmap::{
+pub use crate::graphmap::{
GraphMap,
DiGraphMap,
UnGraphMap,
};
#[doc(no_inline)]
#[cfg(feature = "stable_graph")]
-pub use stable_graph::{
+pub use crate::stable_graph::{
StableGraph,
StableDiGraph,
StableUnGraph,
};
#[doc(no_inline)]
-pub use visit::{
+pub use crate::visit::{
Bfs,
Dfs,
DfsPostOrder,
};
#[doc(no_inline)]
-pub use ::{
+pub use crate::{
Direction,
Incoming,
Outgoing,
@@ -43,6 +43,6 @@
};
#[doc(no_inline)]
-pub use visit::{
+pub use crate::visit::{
EdgeRef,
};
diff --git a/src/quickcheck.rs b/src/quickcheck.rs
index bda1594..7ce6cad 100644
--- a/src/quickcheck.rs
+++ b/src/quickcheck.rs
@@ -1,23 +1,23 @@
extern crate quickcheck;
use self::quickcheck::{Gen, Arbitrary};
-use {
+use crate::{
Graph,
EdgeType,
};
-use graph::{
+use crate::graph::{
IndexType,
node_index,
};
#[cfg(feature = "stable_graph")]
-use stable_graph::StableGraph;
+use crate::stable_graph::StableGraph;
#[cfg(feature = "graphmap")]
-use graphmap::{
+use crate::graphmap::{
GraphMap,
NodeTrait,
};
-use visit::NodeIndexable;
+use crate::visit::NodeIndexable;
/// Return a random float in the range [0, 1.)
fn random_01<G: Gen>(g: &mut G) -> f64 {
@@ -71,7 +71,7 @@
// shrink the graph by splitting it in two by a very
// simple algorithm, just even and odd node indices
- fn shrink(&self) -> Box<Iterator<Item=Self>> {
+ fn shrink(&self) -> Box<dyn Iterator<Item=Self>> {
let self_ = self.clone();
Box::new((0..2).filter_map(move |x| {
let gr = self_.filter_map(|i, w| {
@@ -149,7 +149,7 @@
// shrink the graph by splitting it in two by a very
// simple algorithm, just even and odd node indices
- fn shrink(&self) -> Box<Iterator<Item=Self>> {
+ fn shrink(&self) -> Box<dyn Iterator<Item=Self>> {
let self_ = self.clone();
Box::new((0..2).filter_map(move |x| {
let gr = self_.filter_map(|i, w| {
diff --git a/src/traits_graph.rs b/src/traits_graph.rs
index 90e5fba..1eef177 100644
--- a/src/traits_graph.rs
+++ b/src/traits_graph.rs
@@ -11,10 +11,10 @@
NodeIndex,
};
#[cfg(feature = "stable_graph")]
-use stable_graph::StableGraph;
+use crate::stable_graph::StableGraph;
#[cfg(feature = "stable_graph")]
-use visit::{NodeIndexable, IntoEdgeReferences};
-use visit::EdgeRef;
+use crate::visit::{NodeIndexable, IntoEdgeReferences};
+use crate::visit::EdgeRef;
use super::visit::GetAdjacencyMatrix;
diff --git a/src/visit/dfsvisit.rs b/src/visit/dfsvisit.rs
index 79df937..5ac93c7 100644
--- a/src/visit/dfsvisit.rs
+++ b/src/visit/dfsvisit.rs
@@ -1,7 +1,7 @@
-use visit::IntoNeighbors;
-use visit::{VisitMap, Visitable};
+use crate::visit::IntoNeighbors;
+use crate::visit::{VisitMap, Visitable};
/// Strictly monotonically increasing event time for a depth first search.
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Default, Hash)]
@@ -32,7 +32,7 @@
x => if x.should_break() {
return x;
} else if x.should_prune() {
- $p;
+ $p
}
}
}
diff --git a/src/visit/filter.rs b/src/visit/filter.rs
index cb64c79..7f7c568 100644
--- a/src/visit/filter.rs
+++ b/src/visit/filter.rs
@@ -1,11 +1,11 @@
-use prelude::*;
+use crate::prelude::*;
use fixedbitset::FixedBitSet;
use std::collections::HashSet;
use std::marker::PhantomData;
-use visit::{
+use crate::visit::{
GraphBase,
GraphProp,
IntoEdgeReferences,
@@ -20,8 +20,8 @@
VisitMap,
Visitable,
};
-use visit::{Data, NodeCompactIndexable, NodeCount};
-use data::{DataMap};
+use crate::visit::{Data, NodeCompactIndexable, NodeCount};
+use crate::data::{DataMap};
/// A graph filter for nodes.
pub trait FilterNode<N>
diff --git a/src/visit/mod.rs b/src/visit/mod.rs
index 7383497..d9351f9 100644
--- a/src/visit/mod.rs
+++ b/src/visit/mod.rs
@@ -55,26 +55,26 @@
};
use std::hash::{Hash, BuildHasher};
-use prelude::{Graph, Direction};
+use crate::prelude::{Graph, Direction};
#[cfg(feature = "graphmap")]
-use prelude::GraphMap;
+use crate::prelude::GraphMap;
#[cfg(feature = "stable_graph")]
-use prelude::StableGraph;
-use graph::{NodeIndex};
+use crate::prelude::StableGraph;
+use crate::graph::{NodeIndex};
use super::{
graph,
EdgeType,
};
-use graph::{
+use crate::graph::{
IndexType,
};
#[cfg(feature = "stable_graph")]
-use stable_graph;
-use graph::Frozen;
+use crate::stable_graph;
+use crate::graph::Frozen;
#[cfg(feature = "graphmap")]
-use graphmap::{
+use crate::graphmap::{
self,
NodeTrait,
};
diff --git a/src/visit/reversed.rs b/src/visit/reversed.rs
index 9380aa3..29c6d48 100644
--- a/src/visit/reversed.rs
+++ b/src/visit/reversed.rs
@@ -1,10 +1,10 @@
-use ::{
+use crate::{
Direction,
Incoming,
};
-use visit::{
+use crate::visit::{
GraphBase,
GraphRef,
IntoNodeIdentifiers,
diff --git a/src/visit/traversal.rs b/src/visit/traversal.rs
index d48d083..3a40e7c 100644
--- a/src/visit/traversal.rs
+++ b/src/visit/traversal.rs
@@ -1,5 +1,5 @@
-use {Incoming};
+use crate::{Incoming};
use super::{IntoNeighbors, IntoNeighborsDirected, Visitable, VisitMap};
use super::{GraphRef, Reversed, IntoNodeIdentifiers};
use std::collections::VecDeque;
diff --git a/tests/quickcheck.rs b/tests/quickcheck.rs
index c000c3c..2831a2d 100644
--- a/tests/quickcheck.rs
+++ b/tests/quickcheck.rs
@@ -565,7 +565,7 @@
// shrink the graph by splitting it in two by a very
// simple algorithm, just even and odd node indices
- fn shrink(&self) -> Box<Iterator<Item=Self>> {
+ fn shrink(&self) -> Box<dyn Iterator<Item=Self>> {
let self_ = self.clone();
Box::new((0..2).filter_map(move |x| {
let gr = self_.0.filter_map(|i, w| {
diff --git a/tests/utils/qc.rs b/tests/utils/qc.rs
index a03568e..2715ab1 100644
--- a/tests/utils/qc.rs
+++ b/tests/utils/qc.rs
@@ -19,7 +19,7 @@
Small(T::arbitrary(&mut StdGen::new(g, sz)))
}
- fn shrink(&self) -> Box<Iterator<Item=Self>> {
+ fn shrink(&self) -> Box<dyn Iterator<Item=Self>> {
Box::new((**self).shrink().map(Small))
}
}