ace_it

Crates.ioace_it
lib.rsace_it
version0.1.1
sourcesrc
created_at2023-01-24 13:56:38.182067
updated_at2023-01-25 01:26:28.741362
descriptionMacro to automate wrapping types into enums
homepage
repositoryhttps://github.com/VlaDexa/ace_it
max_upload_size
id766687
size8,584
Vladislav Grechannik (VlaDexa)

documentation

README

ace_it

Auto Convert Enums

Description

Just a small proc_macro to automatically generate From trait impls for each unnamed variant of an enum

Usage

Cargo.toml:

[dependencies]
ace_it = "0.1"

Example

#[macro_use]
extern crate ace_it;

#[derive(Debug)]
#[ace_it]
enum Error {
  Io(std::io::Error),
  ParseInt(std::num::ParseIntError),
  ParseFloat(std::num::ParseFloatError),
}

use std::io::Read;

fn read_int<R: Read>(reader: &mut R) -> Result<i32, Error> {
    let mut buf = String::new();
    reader.read_to_string(&mut buf)?;
    Ok(buf.parse()?)
}

Future features

  • Attribute for ignoring a variant
Commit count: 8

cargo fmt