Skip to content
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ deku_derive = { version = "^0.16.0", path = "deku-derive", default-features = fa
bitvec = { version = "1.0.1", default-features = false }
log = { version = "0.4.17", optional = true }
no_std_io = { version = "0.5.0", default-features = false, features = ["alloc"] }
rustversion = "1.0.15"

[dev-dependencies]
rstest = "0.18.0"
Expand Down
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ use crate::reader::Reader;
use crate::writer::Writer;

/// "Reader" trait: read bytes and bits from [`no_std_io::Read`]er
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
)
)]
pub trait DekuReader<'a, Ctx = ()> {
/// Construct type from `reader` implementing [`no_std_io::Read`], with ctx.
///
Expand Down Expand Up @@ -403,6 +410,13 @@ pub trait DekuReader<'a, Ctx = ()> {

/// "Reader" trait: implemented on DekuRead struct and enum containers. A `container` is a type which
/// doesn't need any context information.
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
)
)]
pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
/// Construct type from Reader implementing [`no_std_io::Read`].
/// * **input** - Input given as "Reader" and bit offset
Expand Down Expand Up @@ -444,6 +458,13 @@ pub trait DekuContainerRead<'a>: DekuReader<'a, ()> {
}

/// "Writer" trait: write from type to bytes
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "implement by adding #[derive(DekuRead)] to `{Self}`",
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
)
)]
pub trait DekuWriter<Ctx = ()> {
/// Write type to bytes
fn to_writer<W: no_std_io::Write>(
Expand All @@ -455,6 +476,13 @@ pub trait DekuWriter<Ctx = ()> {

/// "Writer" trait: implemented on DekuWrite struct and enum containers. A `container` is a type which
/// doesn't need any context information.
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
note = "implement by adding #[derive(DekuWrite)] to `{Self}`",
note = "make sure the `ctx` sent into the function matches `{Self}`'s `ctx`",
)
)]
pub trait DekuContainerWrite: DekuWriter<()> {
/// Write struct/enum to Vec<u8>
///
Expand Down