#macro-derive #forked #abomonation

macro abomonation_derive_ng

A custom derive plugin for abomonation

1 unstable release

0.1.0 Nov 8, 2023

#985 in Procedural macros

Download history 693/week @ 2024-01-03 630/week @ 2024-01-10 367/week @ 2024-01-17 383/week @ 2024-01-24 363/week @ 2024-01-31 684/week @ 2024-02-07 892/week @ 2024-02-14 627/week @ 2024-02-21 510/week @ 2024-02-28 459/week @ 2024-03-06 380/week @ 2024-03-13 263/week @ 2024-03-20 212/week @ 2024-03-27 169/week @ 2024-04-03 254/week @ 2024-04-10 168/week @ 2024-04-17

840 downloads per month
Used in 3 crates

MIT license

17KB
423 lines

abomonation_derive_ng

Derive macro implementation for the Abomonation crate. Forked & improved from the original abomonation_derive crate from @mystor.

This crate provides a custom derive macro #[derive(Abomonation)] for types that should be serializable with the abomonation crate.

Usage

Add this to your Cargo.toml:

[dependencies]
abomonation_derive_ng = "0.1"
abomonation = "0.5"

Then, derive Abomonation on your types:

#[macro_use]
extern crate abomonation_derive_ng;
extern crate abomonation;
use abomonation::Abomonation;

#[derive(Abomonation, PartialEq, Debug)]
struct MyStruct {
    a: u64,
    b: String,
    c: Vec<u8>,
}

// Now you can use `MyStruct` with `abomonation`'s `encode` and `decode`.

Attributes

  • #[abomonation_omit_bounds] : Omits automatic trait bound generation for the Abomonation trait.
  • #[abomonation_bounds(Trait1, Trait2)] : Adds custom trait bounds.
  • #[abomonate_with = "path::to::function"] : Specifies a custom method to use for serialization.
  • #[abomonation_skip] : Skips the field when serializing.

Limitations

The crate does not currently support union types. The use of unsafe is necessary due to the nature of abomonation's serialization technique.

Safety

This crate relies on the same unsafe serialization strategy as abomonation, and the same caveats apply. It is not suitable for untrusted inputs and requires care when used. For detailed information on the safety concerns and how to use this crate, consult the abomonation documentation.

License

This project is licensed under the MIT License, same as the original abomonation-derive crate.

Dependencies

~330–780KB
~19K SLoC