Skip to content

Commit

Permalink
Merge pull request #22 from andyquinterom/T21
Browse files Browse the repository at this point in the history
feat: Implements serialize for NodeVec
  • Loading branch information
andyquinterom authored Oct 22, 2024
2 parents ff7be56 + cbe8f50 commit 65e9cab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orbweaver"
version = "0.15.0"
version = "0.16.0"
edition = "2021"
authors = ["ixpantia <hola@ixpantia.com>", "Andrés F. Quintero <andres@ixpantia.com>"]
description = "Crate designed for effortless construction and analysis of graph data structures."
Expand All @@ -11,6 +11,7 @@ exclude = ["assets/"]

[dev-dependencies]
criterion = "0.5"
serde_json = "1.0.132"
ureq = "2.9.7"

[dependencies]
Expand Down
28 changes: 28 additions & 0 deletions src/utils/node_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ pub struct NodeVec {
pub(crate) arena: Rc<[u8]>,
}

#[cfg(feature = "serde")]
impl serde::Serialize for NodeVec {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.values.serialize(serializer)
}
}

impl PartialEq for NodeVec {
fn eq(&self, other: &Self) -> bool {
self.values.eq(&other.values)
Expand Down Expand Up @@ -110,3 +120,21 @@ impl<'a> Iterator for NodeVecIter<'a> {
self.node_set.values.get(i).copied()
}
}

#[cfg(test)]
mod tests {
use crate::directed::builder::DirectedGraphBuilder;

#[test]
fn test_serialize_nodevec() {
let mut builder = DirectedGraphBuilder::new();
builder.add_path(["0", "1", "2", "3", "4"]);
builder.add_path(["0", "4"]);
let graph = builder.build_acyclic().unwrap();

let paths = graph.find_all_paths("0", "4").unwrap();
let result = serde_json::to_string(&paths).expect("Unable to serialize Vec<NodeVec>");

assert_eq!(result, r#"[["0","1","2","3","4"],["0","4"]]"#);
}
}

0 comments on commit 65e9cab

Please sign in to comment.