clone_into_derive

Crates.ioclone_into_derive
lib.rsclone_into_derive
version0.1.1
sourcesrc
created_at2023-01-03 15:59:26.603128
updated_at2023-01-08 01:26:51.136511
descriptionThis crates generate clone macro for structs. It's quite convenient if you want that a struct copy to another struct which includes the struct fully.
homepage
repositoryhttps://github.com/tak9-n/clone_into_derive
max_upload_size
id750229
size17,884
Takuya Hirata (tak9-n)

documentation

README

clone_into_derive

This crates generate clone macro for structs by the derive macro CloneInto. It's quite convenient if you want to copy a struct to another struct which includes the struct fully, or initialize another struct with the struct.

The derive macro CloneInto generates the macro which clone all of public fields in the struct. The macro name derive from the struct's name. For example, the macro name becomes aaa_bbb_clone_into! if the struct name is AaaBbb.

    #[derive(CloneInto)]
    pub struct AaaBbb {
        pub a: i32,
        pub b: i32,
    }

This code generate aaa_bbb_clone_into! macro. And the aaa_bbb_clone_into!(aaabbb, ccc) is expanded like below.

    ccc.a = aaabbb.a.clone();
    ccc.b = aaabbb.b.clone();

aaa_bbb_ccc_clone!(aaabbb,Ccc{c: 4}) is expanded like below.

    Ccc {
      a: aaabbb.a.clone(),
      b: aaabbb.b.clone(),
      c: 4
    }

You can specify struct name at a place of Ccc. But there is one limit. Now, you can't specify the struct name with path, so you have to specfy just only the struct name. It looks like macro_rules's bug. When I used ty disanator, The macro expansion result became an error.

The example is in tests directory.

Commit count: 15

cargo fmt