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.
This commit is contained in:
parent
9c96a79a74
commit
85c2c2e38c
24 changed files with 120 additions and 129 deletions
|
|
@ -28,13 +28,13 @@ pub fn highlight(src: &str, class: Option<&str>, id: Option<&str>) -> String {
|
|||
src.to_string(),
|
||||
"<stdin>".to_string());
|
||||
|
||||
let mut out = io::MemWriter::new();
|
||||
let mut out = Vec::new();
|
||||
doit(&sess,
|
||||
lexer::StringReader::new(&sess.span_diagnostic, fm),
|
||||
class,
|
||||
id,
|
||||
&mut out).unwrap();
|
||||
String::from_utf8_lossy(out.unwrap().as_slice()).into_string()
|
||||
String::from_utf8_lossy(out[]).into_string()
|
||||
}
|
||||
|
||||
/// Exhausts the `lexer` writing the output into `out`.
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use std::collections::{HashMap, HashSet};
|
|||
use std::collections::hash_map::{Occupied, Vacant};
|
||||
use std::fmt;
|
||||
use std::io::fs::PathExtensions;
|
||||
use std::io::{fs, File, BufferedWriter, MemWriter, BufferedReader};
|
||||
use std::io::{fs, File, BufferedWriter, BufferedReader};
|
||||
use std::io;
|
||||
use std::str;
|
||||
use std::string::String;
|
||||
|
|
@ -420,7 +420,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
|
|||
}
|
||||
|
||||
// Collect the index into a string
|
||||
let mut w = MemWriter::new();
|
||||
let mut w = Vec::new();
|
||||
try!(write!(&mut w, r#"searchIndex['{}'] = {{"items":["#, krate.name));
|
||||
|
||||
let mut lastpath = "".to_string();
|
||||
|
|
@ -463,7 +463,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
|
|||
|
||||
try!(write!(&mut w, "]}};"));
|
||||
|
||||
Ok(String::from_utf8(w.unwrap()).unwrap())
|
||||
Ok(String::from_utf8(w).unwrap())
|
||||
}
|
||||
|
||||
fn write_shared(cx: &Context,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ extern crate "test" as testing;
|
|||
#[phase(plugin, link)] extern crate log;
|
||||
|
||||
use std::io;
|
||||
use std::io::{File, MemWriter};
|
||||
use std::io::File;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::{Occupied, Vacant};
|
||||
use serialize::{json, Decodable, Encodable};
|
||||
|
|
@ -467,12 +467,12 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
|||
// FIXME #8335: yuck, Rust -> str -> JSON round trip! No way to .encode
|
||||
// straight to the Rust JSON representation.
|
||||
let crate_json_str = {
|
||||
let mut w = MemWriter::new();
|
||||
let mut w = Vec::new();
|
||||
{
|
||||
let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
|
||||
krate.encode(&mut encoder).unwrap();
|
||||
}
|
||||
String::from_utf8(w.unwrap()).unwrap()
|
||||
String::from_utf8(w).unwrap()
|
||||
};
|
||||
let crate_json = match json::from_str(crate_json_str.as_slice()) {
|
||||
Ok(j) => j,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue