2014-02-13 06:31:19 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-17 15:33:26 -05:00
|
|
|
use std::io::Write;
|
2014-05-17 00:40:38 -05:00
|
|
|
use std::fmt;
|
2014-02-13 06:31:19 -06:00
|
|
|
|
|
|
|
struct Foo<'a> {
|
2015-03-17 15:33:26 -05:00
|
|
|
writer: &'a mut (Write+'a),
|
2014-02-13 06:31:19 -06:00
|
|
|
other: &'a str,
|
|
|
|
}
|
|
|
|
|
2014-05-17 00:40:38 -05:00
|
|
|
struct Bar;
|
|
|
|
|
2015-02-13 17:56:32 -06:00
|
|
|
impl fmt::Write for Bar {
|
2014-12-12 12:59:41 -06:00
|
|
|
fn write_str(&mut self, _: &str) -> fmt::Result {
|
2014-05-17 00:40:38 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 06:31:19 -06:00
|
|
|
fn borrowing_writer_from_struct_and_formatting_struct_field(foo: Foo) {
|
|
|
|
write!(foo.writer, "{}", foo.other);
|
|
|
|
}
|
|
|
|
|
2014-05-11 13:14:14 -05:00
|
|
|
fn main() {
|
2015-03-17 15:33:26 -05:00
|
|
|
let mut w = Vec::new();
|
|
|
|
write!(&mut w as &mut Write, "");
|
2014-02-13 06:31:19 -06:00
|
|
|
write!(&mut w, ""); // should coerce
|
2014-05-11 13:14:14 -05:00
|
|
|
println!("ok");
|
2014-05-17 00:40:38 -05:00
|
|
|
|
|
|
|
let mut s = Bar;
|
2014-12-12 12:59:41 -06:00
|
|
|
{
|
2015-02-13 17:56:32 -06:00
|
|
|
use std::fmt::Write;
|
2014-12-12 12:59:41 -06:00
|
|
|
write!(&mut s, "test");
|
|
|
|
}
|
2014-02-13 06:31:19 -06:00
|
|
|
}
|