RustMagazine / rust_magazine_2021

RustMagazine 2021 期刊 (已完结)
https://rustmagazine.github.io/rust_magazine_2021/
MIT License
1.19k stars 113 forks source link

Rust过程宏系列教程 | Proc Macro Workshop 之 Builder 实现 - Rust精选 #98

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Rust过程宏系列教程 | Proc Macro Workshop 之 Builder 实现 - Rust精选

The roots aren't deep but the seeds are planted!

https://rustmagazine.github.io/rust_magazine_2021/chapter_5/proc_macro_workshop_guide_for_builder_project.html

iamazy commented 3 years ago

感谢爆米花这篇文章,写得非常好,但是我看一些代码可能是加了注释之后把原来的代码给误删了,不是很完整,不过我又参考了下博客原文,疑问得到解决

TigerInYourDream commented 3 years ago

派生宏教程第二关最后的函数下面少加了东西

let ret = quote! {
        pub struct #builder_name_ident {
        }
        impl #struct_ident {
            pub fn builder() -> #builder_name_ident {
                    // 下面这一行是新加的,注意我们在这里重复展开了每一个字段
                }
            }
        }
    };

看了下原博客是有的,新加的这句是这个

#(#builder_struct_factory_init_clauses),*

看的朋友注意下