Reputation: 5223
I'm trying to make sure I understand all the examples on http://chrismorgan.info/blog/rust-fizzbuzz.html, and the one thing I am stuck on has nothing to do with FizzBuzz, but instead the arguments to write().
Consider the code below: in a line like Fizz => f.write(b"Fizz")
, what is 'b' and where did it come from?
use std::fmt;
enum FizzBuzzItem {
Fizz,
Buzz,
FizzBuzz,
Number(int),
}
impl fmt::Show for FizzBuzzItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Fizz => f.write(b"Fizz"),
Buzz => f.write(b"Buzz"),
FizzBuzz => f.write(b"FizzBuzz"),
Number(num) => write!(f, "{}", num),
}
}
}
Upvotes: 0
Views: 164
Reputation: 90752
b"…"
is a byte string literal. As "…"
has the type &'static str
, it has the type &'static [u8]
.
Upvotes: 2