0

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)

Omar Abid
  • 15,753
  • 28
  • 77
  • 108
  • 1
    The `write!` macro requires a buffer to write to. In your case, such a buffer is provided by the formatter. So, the correct invocation would be `write!(f, "...")`. – Andrew Lygin Sep 06 '17 at 19:34
  • I don't know but I think the error message is not quite informative. – Omar Abid Sep 06 '17 at 19:44

1 Answers1

1

write! expects the output buffer as its first argument:

write!(f, "Nothing seriously")
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127