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

feat: Add support for more packages to DeepSize #18

Merged
merged 1 commit into from
Nov 19, 2021
Merged
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ arrayvec = { version = "^0.5", optional = true }
smallvec = { version = "^1", optional = true }
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 }

[dev-dependencies]
deepsize_derive = { path = "deepsize_derive", version = "0.1.1" }
Expand All @@ -28,3 +30,4 @@ deepsize_derive = { path = "deepsize_derive", version = "0.1.1" }
default = ["std", "derive"]
derive = ["deepsize_derive"]
std = []
tokio_net = ["tokio", "tokio/net"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ references, and are not counted.
* `smallvec`: (version 1)
* `hashbrown`: (version 0.9)
* `chrono`: (version 0.4)
* `actix`: (version 0.11)
* `tokio`: (version 1.1)

## Example Code

Expand All @@ -54,7 +56,7 @@ fn main() {
a: 15,
b: Box::new(*b"Hello, Wold!"),
};

assert_eq!(object.deep_size_of(), size_of::<Test>() + size_of::<u8>() * 12);
}
```
Expand Down
23 changes: 23 additions & 0 deletions src/external_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,26 @@ mod chrono_impl {
{T: TimeZone} DateTime<T>, {T: TimeZone} Date<T>,
);
}

#[cfg(feature = "tokio_net")]
mod tokio_net_impl {
use crate::known_deep_size;
use tokio::net::{TcpListener, TcpStream, UdpSocket, UnixDatagram, UnixListener, UnixStream};

known_deep_size!(0;
TcpListener, TcpStream, UdpSocket,
UnixDatagram, UnixListener, UnixStream
);
}

#[cfg(feature = "actix")]
mod actix_impl {
use crate::{Context, DeepSizeOf};
use actix::Addr;

impl<T: actix::Actor> DeepSizeOf for Addr<T> {
fn deep_size_of_children(&self, _context: &mut Context) -> usize {
0
}
}
}