Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ hashbrown = { version = "^0.9", optional = true }
chrono = { version = "^0.4", optional = true }
tokio = { version = "^1.1", optional = true, default-features = false }
actix = { version = "^0.11.0", optional = true, default-features = false }
cpe = { version= "0.1.5" , optional = true }
petgraph = { version = "0.7.1", optional = true, features = ["serde-1"] }

[dev-dependencies]
deepsize_derive = { path = "deepsize_derive", version = "0.1.1" }
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ references, and are not counted.
* `chrono`: (version 0.4)
* `actix`: (version 0.11)
* `tokio`: (version 1.1)
* `cpe`: (version 0.1.5)
* `petgraph`: (version 0.7.1)

## Example Code

Expand Down
67 changes: 67 additions & 0 deletions src/external_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,70 @@ mod actix_impl {
}
}
}

#[cfg(feature = "cpe")]
mod cpe_impl {
use crate::{Context, DeepSizeOf};
use cpe::component::OwnedComponent;
use cpe::cpe::{Cpe, Language};
use cpe::uri::OwnedUri;

impl DeepSizeOf for OwnedComponent {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
if let OwnedComponent::Value(v) = self {
v.deep_size_of_children(ctx)
} else {
0
}
}
}

impl DeepSizeOf for Language {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
if let Language::Language(v) = self {
v.as_str().deep_size_of_children(ctx)
} else {
0
}
}
}

impl DeepSizeOf for OwnedUri {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
self.vendor().to_owned().deep_size_of_children(ctx)
+ self.product().to_owned().deep_size_of_children(ctx)
+ self.version().to_owned().deep_size_of_children(ctx)
+ self.update().to_owned().deep_size_of_children(ctx)
+ self.edition().to_owned().deep_size_of_children(ctx)
+ self.sw_edition().to_owned().deep_size_of_children(ctx)
+ self.target_sw().to_owned().deep_size_of_children(ctx)
+ self.other().to_owned().deep_size_of_children(ctx)
+ self.language().to_owned().deep_size_of_children(ctx)
}
}
}

#[cfg(feature = "petgraph")]
mod petgraph_impl {
use crate::{Context, DeepSizeOf};
use petgraph::graph::{Edge, Graph, Node};

impl<N: DeepSizeOf> DeepSizeOf for Node<N> {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
self.weight.deep_size_of_children(ctx)
}
}

impl<E: DeepSizeOf> DeepSizeOf for Edge<E> {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
self.weight.deep_size_of_children(ctx)
}
}

impl<N: DeepSizeOf, E: DeepSizeOf> DeepSizeOf for Graph<N, E> {
fn deep_size_of_children(&self, ctx: &mut Context) -> usize {
self.raw_nodes().deep_size_of_children(ctx)
+ self.raw_edges().deep_size_of_children(ctx)
}
}
}