Search code examples
rustrust-macros

Unexpected end of macro invocation in Rust


I have the following code in 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 ); 
}

At Compile, I'm getting the following error

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

I'm not exactly certain what the problem is.

Edit: I'm using the latest Rust version (Stable 1.20)


Solution

  • write! expects the output buffer as its first argument:

    write!(f, "Nothing seriously")