#context #derive #different #generate #maps #macro #context-mapper

过程宏 context-mapper-derive

context-mapper derive 库

1 个不稳定版本

0.1.0 2024年2月4日

#130#maps


context-mapper 中使用

MITGPL-3.0-only

31KB
692

Context Mapper

一个用于生成不同映射的Rust宏

示例

#[derive(ContextMapper)]
#[context_mapper(
    impl(
        context = info::general
        converter = MyConv::to_info,
        type = info::Info,
        fn = general_info
        vis = pub(crate)
    ),
    function(
        context = info::all
        converter = MyConv::to_info,
        type = info::Info,
        fn = all_info
    ),

)]
struct Person {
    name: String,
    address: info::Address,
    age: usize,

    /// Let's hide it for the geneal info, but show for the rest
    #[context_attribute(context(name=info::general, skip))]
    is_a_reptile: bool
}

//

let person = Person {
    //
};

person.general_info();
all_info(&person);

依赖项

~0.7–1.2MB
~22K SLoC