about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2014-11-11 16:01:29 -0500
committerDaniel Micay <danielmicay@gmail.com>2014-11-18 01:09:46 -0500
commit85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8 (patch)
tree578802f9e774e104b1a271b92946208e0e0a0675 /src/test
parent9c96a79a74f10bed18b031ce0ac4126c56d6cfb3 (diff)
downloadrust-85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8.tar.gz
rust-85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8.zip
implement Writer for Vec<u8>
The trait has an obvious, sensible implementation directly on vectors so
the MemWriter wrapper is unnecessary. This will halt the trend towards
providing all of the vector methods on MemWriter along with eliminating
the noise caused by conversions between the two types. It also provides
the useful default Writer methods on Vec<u8>.

After the type is removed and code has been migrated, it would make
sense to add a new implementation of MemWriter with seeking support. The
simple use cases can be covered with vectors alone, and ones with the
need for seeks can use a new MemWriter implementation.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/variance-trait-matching-2.rs5
-rw-r--r--src/test/run-pass/auto-encode.rs5
-rw-r--r--src/test/run-pass/colorful-write-macros.rs2
-rw-r--r--src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs1
-rw-r--r--src/test/run-pass/deriving-encodable-decodable.rs5
-rw-r--r--src/test/run-pass/ifmt.rs10
6 files changed, 11 insertions, 17 deletions
diff --git a/src/test/compile-fail/variance-trait-matching-2.rs b/src/test/compile-fail/variance-trait-matching-2.rs
index f549c78be9d..ed4fdc52572 100644
--- a/src/test/compile-fail/variance-trait-matching-2.rs
+++ b/src/test/compile-fail/variance-trait-matching-2.rs
@@ -10,7 +10,6 @@
 
 extern crate serialize;
 
-use std::io::MemWriter;
 use std::io;
 use serialize::{Encodable, Encoder};
 
@@ -18,14 +17,14 @@ pub fn buffer_encode<'a,
                      T:Encodable<serialize::json::Encoder<'a>,io::IoError>>(
                      to_encode_object: &T)
                      -> Vec<u8> {
-    let mut m = MemWriter::new();
+    let mut m = Vec::new();
     {
         let mut encoder =
             serialize::json::Encoder::new(&mut m as &mut io::Writer);
         //~^ ERROR `m` does not live long enough
         to_encode_object.encode(&mut encoder);
     }
-    m.unwrap()
+    m
 }
 
 fn main() {}
diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs
index 44006a0039a..3fc2ed5468a 100644
--- a/src/test/run-pass/auto-encode.rs
+++ b/src/test/run-pass/auto-encode.rs
@@ -31,12 +31,11 @@ fn test_rbml<'a, 'b, A:
     Encodable<EBWriter::Encoder<'a>> +
     Decodable<EBReader::Decoder<'b>>
 >(a1: &A) {
-    let mut wr = std::io::MemWriter::new();
+    let mut wr = Vec::new();
     let mut rbml_w = EBwriter::Encoder::new(&mut wr);
     a1.encode(&mut rbml_w);
-    let bytes = wr.get_ref();
 
-    let d: serialize::rbml::Doc<'a> = EBDoc::new(bytes);
+    let d: serialize::rbml::Doc<'a> = EBDoc::new(wr[]);
     let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
     let a2: A = Decodable::decode(&mut decoder);
     assert!(*a1 == a2);
diff --git a/src/test/run-pass/colorful-write-macros.rs b/src/test/run-pass/colorful-write-macros.rs
index 60b6d8f8be0..75b8e391331 100644
--- a/src/test/run-pass/colorful-write-macros.rs
+++ b/src/test/run-pass/colorful-write-macros.rs
@@ -10,7 +10,7 @@
 
 // no-pretty-expanded
 
-#![allow(unused_must_use, dead_code)]
+#![allow(unused_must_use, dead_code, deprecated)]
 #![feature(macro_rules)]
 
 use std::io::MemWriter;
diff --git a/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs b/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs
index 7164547b6b8..a846f852694 100644
--- a/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs
+++ b/src/test/run-pass/deriving-encodable-decodable-cell-refcell.rs
@@ -14,7 +14,6 @@
 extern crate serialize;
 
 use std::cell::{Cell, RefCell};
-use std::io::MemWriter;
 use serialize::{Encodable, Decodable};
 use serialize::json;
 
diff --git a/src/test/run-pass/deriving-encodable-decodable.rs b/src/test/run-pass/deriving-encodable-decodable.rs
index 573b57fb44a..021b609efe2 100644
--- a/src/test/run-pass/deriving-encodable-decodable.rs
+++ b/src/test/run-pass/deriving-encodable-decodable.rs
@@ -19,7 +19,6 @@ extern crate rand;
 extern crate rbml;
 extern crate serialize;
 
-use std::io::MemWriter;
 use rand::{random, Rand};
 use rbml;
 use rbml::Doc;
@@ -59,10 +58,10 @@ struct G<T> {
 fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
                     Decodable<Decoder<'a>>>() {
     let obj: T = random();
-    let mut w = MemWriter::new();
+    let mut w = Vec::new();
     let mut e = Encoder::new(&mut w);
     obj.encode(&mut e);
-    let doc = rbml::Doc::new(@w.get_ref());
+    let doc = rbml::Doc::new(@w[]);
     let mut dec = Decoder::new(doc);
     let obj2 = Decodable::decode(&mut dec);
     assert!(obj == obj2);
diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs
index b384d7c5583..59f7eda4161 100644
--- a/src/test/run-pass/ifmt.rs
+++ b/src/test/run-pass/ifmt.rs
@@ -16,9 +16,7 @@
 #![allow(unused_must_use)]
 
 use std::fmt;
-use std::io::MemWriter;
 use std::io;
-use std::str;
 
 struct A;
 struct B;
@@ -161,7 +159,7 @@ pub fn main() {
 // Basic test to make sure that we can invoke the `write!` macro with an
 // io::Writer instance.
 fn test_write() {
-    let mut buf = MemWriter::new();
+    let mut buf = Vec::new();
     write!(&mut buf as &mut io::Writer, "{}", 3i);
     {
         let w = &mut buf as &mut io::Writer;
@@ -171,7 +169,7 @@ fn test_write() {
         writeln!(w, "{foo}", foo="bar");
     }
 
-    let s = str::from_utf8(buf.unwrap().as_slice()).unwrap().to_string();
+    let s = String::from_utf8(buf).unwrap();
     t!(s, "34helloline\nbar\n");
 }
 
@@ -188,14 +186,14 @@ fn test_print() {
 // Just make sure that the macros are defined, there's not really a lot that we
 // can do with them just yet (to test the output)
 fn test_format_args() {
-    let mut buf = MemWriter::new();
+    let mut buf = Vec::new();
     {
         let w = &mut buf as &mut io::Writer;
         format_args!(|args| { write!(w, "{}", args); }, "{}", 1i);
         format_args!(|args| { write!(w, "{}", args); }, "test");
         format_args!(|args| { write!(w, "{}", args); }, "{test}", test=3i);
     }
-    let s = str::from_utf8(buf.unwrap().as_slice()).unwrap().to_string();
+    let s = String::from_utf8(buf).unwrap();
     t!(s, "1test3");
 
     let s = format_args!(fmt::format, "hello {}", "world");