19 releases

0.0.19 Dec 17, 2025
0.0.18 Nov 8, 2024
0.0.17 Jun 14, 2024
0.0.16 Jan 16, 2024
0.0.3 Dec 14, 2021

#2028 in Rust patterns

Download history 339581/week @ 2025-08-27 348778/week @ 2025-09-03 354761/week @ 2025-09-10 351858/week @ 2025-09-17 370862/week @ 2025-09-24 382723/week @ 2025-10-01 385760/week @ 2025-10-08 400761/week @ 2025-10-15 438605/week @ 2025-10-22 478063/week @ 2025-10-29 460763/week @ 2025-11-05 490208/week @ 2025-11-12 493722/week @ 2025-11-19 389881/week @ 2025-11-26 571658/week @ 2025-12-03 569139/week @ 2025-12-10

2,110,824 downloads per month
Used in 176 crates (10 directly)

MIT license

185KB
3.5K SLoC

Due to a doxxing incident bincode development has officially ceased and will not resume. Updates will only be pushed to the in the unlikely event of CVEs. Do not contact us for any other reason.

To those of you who bothered doxxing us. Go touch grass and maybe for once consider your actions have consequences for real people.

Fuck off and worst regards, The Bincode Team

Virtue, a sinless derive macro helper

Goals

  • Zero dependencies, so fast compile times
  • No other dependencies needed
  • Declarative code generation
  • As much typesystem checking as possible
  • Build for modern rust: 1.57 and up
  • Build with popular crates in mind:
  • Will always respect semver. Minor releases will never have:
    • Breaking API changes
    • MSRV changes

Example

use virtue::prelude::*;

#[proc_macro_derive(YourDerive, attributes(some, attributes, go, here))]
pub fn derive_your_derive(input: TokenStream) -> TokenStream {
    derive_your_derive_inner(input)
        .unwrap_or_else(|error| error.into_token_stream())
}

fn derive_your_derive_inner(input: TokenStream) -> Result<TokenStream> {
    // Parse the struct or enum you want to implement a derive for
    let parse = Parse::new(input)?;
    // Get a reference to the generator
    let (mut generator, body) = parse.into_generator();
    match body {
        Body::Struct(body) => {
            // Implement your struct body here
            // See `Generator` for more information
            generator.impl_for("YourTrait")?
                    .generate_fn("your_fn")
                    .with_self_arg(FnSelfArg::RefSelf)
                    .body(|fn_body| {
                        fn_body.push_parsed("println!(\"Hello world\");");
                    })?;
        },
        Body::Enum(body) => {
            // Implement your enum body here
            // See `Generator` for more information
            generator.impl_for("YourTrait")?
                    .generate_fn("your_fn")
                    .with_self_arg(FnSelfArg::RefSelf)
                    .body(|fn_body| {
                        fn_body.push_parsed("println!(\"Hello world\");");
                    })?;
        },
    }
    generator.finish()
}

Will generate

impl YourTrait for <Struct or Enum> {
    fn your_fn(&self) { // .generate_fn("your_fn").with_self_arg(FnSelfArg::RefSelf)
        println!("Hello world"); // fn_body.push_parsed(...)
    }
}

Dependencies