Skip to content

Commit 3a5082e

Browse files
committed
traits: Copy traits from netlink-core-utils
Signed-off-by: Enrique Llorente <[email protected]>
1 parent ba3e39e commit 3a5082e

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ repository = "https://github.com/rust-netlink/netlink-packet-core"
1212
description = "netlink packet types"
1313

1414
[dependencies]
15-
anyhow = "1.0.31"
1615
byteorder = "1.3.2"
17-
netlink-packet-utils = "0.6.0"
1816

1917
[dev-dependencies]
2018
netlink-packet-route = "0.13.0"

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,3 @@ pub use self::message::*;
267267

268268
pub mod constants;
269269
pub use self::constants::*;
270-
271-
pub(crate) use self::utils::traits::*;
272-
pub(crate) use netlink_packet_utils as utils;

src/traits.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,46 @@ pub trait NetlinkSerializable {
4141
/// This method panics if the buffer is not big enough.
4242
fn serialize(&self, buffer: &mut [u8]);
4343
}
44+
45+
/// A type that implements `Emitable` can be serialized.
46+
pub trait Emitable {
47+
/// Return the length of the serialized data.
48+
fn buffer_len(&self) -> usize;
49+
50+
/// Serialize this types and write the serialized data into the given
51+
/// buffer.
52+
///
53+
/// # Panic
54+
///
55+
/// This method panic if the buffer is not big enough. You **must** make
56+
/// sure the buffer is big enough before calling this method. You can
57+
/// use [`buffer_len()`](trait.Emitable.html#method.buffer_len) to check
58+
/// how big the storage needs to be.
59+
fn emit(&self, buffer: &mut [u8]);
60+
}
61+
62+
/// A `Parseable` type can be used to deserialize data from the type `T` for
63+
/// which it is implemented.
64+
pub trait Parseable<T>
65+
where
66+
Self: Sized,
67+
T: ?Sized,
68+
{
69+
type Error;
70+
71+
/// Deserialize the current type.
72+
fn parse(buf: &T) -> Result<Self, Self::Error>;
73+
}
74+
75+
/// A `Parseable` type can be used to deserialize data from the type `T` for
76+
/// which it is implemented.
77+
pub trait ParseableParametrized<T, P>
78+
where
79+
Self: Sized,
80+
T: ?Sized,
81+
{
82+
type Error;
83+
84+
/// Deserialize the current type.
85+
fn parse_with_param(buf: &T, params: P) -> Result<Self, Self::Error>;
86+
}

0 commit comments

Comments
 (0)