gpt4 book ai didi

macros - 我如何在稳定的 Rust 中使用宏值作为函数名的一部分?

转载 作者:行者123 更新时间:2023-11-29 08:07:51 26 4
gpt4 key购买 nike

<分区>

我正在尝试编写这样的宏:

macro_rules! impl_numeric_cast_methods {
($($ty:ty)*) => {
$(
fn from_$ty(v: $ty) -> Self {
v as Self
}
)*
}
}

from_$ty 位由于宏卫生问题而不起作用。我发现如果 $ty 是一个 ident 那么我可以(在不稳定的情况下)可能使用 concat_idents!除了apparently doesn't work either .

a blog post about this issue以及 future 修复它的计划,但我的问题是:在今天的 Rust 稳定版 (1.15) 中我怎么能做到这一点?有解决方法吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com