小编cha*_*dge的帖子

不支持 PostgreSQL 身份验证方法 10

我正在尝试使用 PostgreSQL 遵循diesel.rs 教程。当我进入 Diesel 设置步骤时,收到“不支持身份验证方法 10”错误。我该如何解决?

postgresql rust rust-diesel

19
推荐指数
2
解决办法
11万
查看次数

如何在 Rust 中创建匹配宏?

我正在尝试完成 Rustlings 练习中的测验 #4:

// 编写一个通过测验的宏!这次没有提示,你可以做到!

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_my_macro_world() {
        assert_eq!(my_macro!("world!"), "Hello world!");
    }

    #[test]
    fn test_my_macro_goodbye() {
        assert_eq!(my_macro!("goodbye!"), "Hello goodbye!");
    }
}
Run Code Online (Sandbox Code Playgroud)

我的宏看起来像这样:

#[macro_export]
macro_rules! my_macro {
    (($val:expr), "world!") => {
        println!("Hello world!");
    };
    (($val:expr), "goodbye!") => {
        println!("Hello goodbye!");
    };
}
Run Code Online (Sandbox Code Playgroud)

这是在 Rust 语言文档的声明性宏部分之后设计的。我收到以下错误:

assert_eq!(my_macro!("world!"), "Hello world!");
   |                              ^^^^^^^^^^ no rules expected this token in macro call

assert_eq!(my_macro!("goodbye!"), "Hello goodbye!");
   |                              ^^^^^^^^^^ no rules expected this token in macro call
Run Code Online (Sandbox Code Playgroud)

我找不到解决此问题的解决方案以使其编译。帮助!

rust rust-macros

1
推荐指数
1
解决办法
699
查看次数

标签 统计

rust ×2

postgresql ×1

rust-diesel ×1

rust-macros ×1