当按照相应博客文章的建议使用稳定的serde时,必须使用内置宏来提取由serde-codegen生成的文件.include!
这里链接的文件在一个更复杂的例子中显示了这个,它可以使用rustc nightly和rustc stable.
然而,正如建议的文档include!,它不卫生行为.
这意味着我不清楚,直到我遇到一个问题,即在外部包中定义的宏,yup-hyper-mock,没有在包含时定义.一些测试表明即使是类似的东西extern crate foo-bar-snoo-snoo;也不会在包含时触发错误,表明它还没有被评估过.
问题来自于include!尝试扩展宏,如果这些宏来自尚未评估的外部包装箱,则会失败.
我尝试使用正确的签名来定义空宏会导致include!宏工作,但编译会在以后失败,因为include!实际上会立即扩展宏,这在包含时是空的.
有没有办法include!在外部板条箱中定义宏?或者,你能想象一个解决方法来使我的特定案例有效吗?
我个人认为include!根本不应该扩展宏,但是将其留给下一个应该引入外部包装箱的编译步骤 - 也许我们正在查看一个错误rustc,但我不确定.
请注意,稳定和夜间编译器都显示相同的问题.
git clone --branch syntex https://github.com/Byron/yup-oauth2
cd yup-oauth2
git reset --hard f59d97d
# build and test fail because 'include!' runs before crates are pulled
# in, but still expands macros
cargo build
cargo test
Run Code Online (Sandbox Code Playgroud)
稳定
? yup-oauth2 git:(syntex) rustc --version --verbose
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37e99060162a2674e3ff45409ac73595c0e
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-apple-darwin
release: 1.0.0
Run Code Online (Sandbox Code Playgroud)
每夜
? yup-oauth2 git:(syntex) rustc --version --verbose
rustc 1.2.0-nightly (2228ce10c 2015-06-09)
binary: rustc
commit-hash: 2228ce10c6d83c17b6346396aa7c7ef9082f1c04
commit-date: 2015-06-09
host: x86_64-apple-darwin
release: 1.2.0-nightly
Run Code Online (Sandbox Code Playgroud)