Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macros 在Rust宏中操纵路径?_Macros_Rust - Fatal编程技术网

Macros 在Rust宏中操纵路径?

Macros 在Rust宏中操纵路径?,macros,rust,Macros,Rust,我想写一个宏,可以分解一条路径来操作它的组件。例如: macro_rules! example { ($path:path) => { vec![ stringify!(get_path_init!($path)), stringify!(get_path_last!($path)), ] }; } fn main() { let path_parts = example!(std::

我想写一个宏,可以分解一条路径来操作它的组件。例如:

macro_rules! example {
    ($path:path) => {
        vec![
            stringify!(get_path_init!($path)),
            stringify!(get_path_last!($path)),
        ]
    };
}

fn main() {
    let path_parts = example!(std::vec::Vec);
    assert_eq!(path_parts, vec!["std::vec", "Vec"]);
}

在标准库或任何合理流行的板条箱中是否存在类似的内容,是否可以使用宏实现?或者它需要一个编译器插件?

它需要一个编译器插件;这不能用
宏规则来完成,也不是语言或标准库的一部分,而且任何这样做的板条箱(据我所知没有)无论如何都需要每晚的编译器