into-from

Crates.iointo-from
lib.rsinto-from
version
sourcesrc
created_at2024-12-12 08:55:14.350509
updated_at2024-12-12 09:04:11.267335
descriptionRust macro for impl Into or From for Struct
homepage
repositoryhttps://github.com/cody-why/macro-into
max_upload_size
id1481011
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
plucky (cody-why)

documentation

https://docs.rs/crate/macro-into/

README

Crates.io Docs Download

Macro Into

Rust macro for auto impl Into<T> or From<T> for Struct

Usage

impl Into<Bar> for Foo

struct Foo {
    field1: i32,
    field3: String,
}

#[into(Foo)]
struct Bar {
    field1: i32,
    #[into_skip]
    field2: String,
    #[into(self.field3.to_string())]
    field3: i32,
}

Auto generated code:

impl Into<Foo> for Bar {
    fn into(self) -> Foo {
        Foo {
            field1: self.field1,
            field3: self.field3.to_string(),
        }
    }
}

impl From<Bar> for Foo

struct Foo {
    field1: i32,
    field2: String,
}

#[from(Foo)]
struct Bar {
    field1: i32,
    #[from(source.field2.parse::<i32>().unwrap())]
    field3: i32,
}

Auto generated code:

impl From<Foo> for Bar {
    fn from(source: Foo) -> Self {
        Bar {
            field1: source.field1,
            field3: source.field2.parse::<i32>().unwrap(),
        }
    }
}
Commit count: 5

cargo fmt