首页 文章

Rust中宏调用的意外结束

提问于
浏览
0

我在Rust中有以下代码

use std::fmt;

pub struct MyRange<Idx> {
    pub start: Idx,
    pub end: Idx,
}

impl fmt::Debug for MyRange<f32>  {
    fn fmt( &self, f: &mut fmt::Formatter ) -> fmt::Result {
        write!( "Nothing seriously" )
    }
}

fn main() {
    let start:f32= 1.2;
    let end:f32 = 5.;
    let rng2 = MyRange { start: start, end: end};
    println!( "{:?}", rng2 ); 
}

在Compile,我收到以下错误

error: unexpected end of macro invocation
  --> src/main.rs:10:17
   |
10 |         write!( "Nothing seriously" )
   |                 ^^^^^^^^^^^^^^^^^^^

我不确定问题是什么 .

编辑:我正在使用最新的Rust版本(稳定1.20)

1 回答

  • 1

    write!期望输出缓冲区作为其第一个参数:

    write!(f, "Nothing seriously")
    

相关问题