|
48 | 48 | //!
|
49 | 49 | //! ```rust
|
50 | 50 | //! use std::borrow::IntoCow;
|
| 51 | +//! use std::io::Write; |
51 | 52 | //! use graphviz as dot;
|
52 | 53 | //!
|
53 | 54 | //! type Nd = int;
|
54 | 55 | //! type Ed = (int,int);
|
55 | 56 | //! struct Edges(Vec<Ed>);
|
56 | 57 | //!
|
57 |
| -//! pub fn render_to<W:Writer>(output: &mut W) { |
| 58 | +//! pub fn render_to<W: Write>(output: &mut W) { |
58 | 59 | //! let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
|
59 | 60 | //! dot::render(&edges, output).unwrap()
|
60 | 61 | //! }
|
|
94 | 95 | //! ```
|
95 | 96 | //!
|
96 | 97 | //! ```no_run
|
97 |
| -//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() } |
| 98 | +//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() } |
98 | 99 | //! pub fn main() {
|
99 |
| -//! use std::old_io::File; |
100 |
| -//! let mut f = File::create(&Path::new("example1.dot")); |
| 100 | +//! use std::fs::File; |
| 101 | +//! let mut f = File::create("example1.dot").unwrap(); |
101 | 102 | //! render_to(&mut f)
|
102 | 103 | //! }
|
103 | 104 | //! ```
|
|
148 | 149 | //!
|
149 | 150 | //! ```rust
|
150 | 151 | //! use std::borrow::IntoCow;
|
| 152 | +//! use std::io::Write; |
151 | 153 | //! use graphviz as dot;
|
152 | 154 | //!
|
153 | 155 | //! type Nd = uint;
|
154 | 156 | //! type Ed<'a> = &'a (uint, uint);
|
155 | 157 | //! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
|
156 | 158 | //!
|
157 |
| -//! pub fn render_to<W:Writer>(output: &mut W) { |
| 159 | +//! pub fn render_to<W: Write>(output: &mut W) { |
158 | 160 | //! let nodes = vec!("{x,y}","{x}","{y}","{}");
|
159 | 161 | //! let edges = vec!((0,1), (0,2), (1,3), (2,3));
|
160 | 162 | //! let graph = Graph { nodes: nodes, edges: edges };
|
|
186 | 188 | //! ```
|
187 | 189 | //!
|
188 | 190 | //! ```no_run
|
189 |
| -//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() } |
| 191 | +//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() } |
190 | 192 | //! pub fn main() {
|
191 |
| -//! use std::old_io::File; |
192 |
| -//! let mut f = File::create(&Path::new("example2.dot")); |
| 193 | +//! use std::fs::File; |
| 194 | +//! let mut f = File::create("example2.dot").unwrap(); |
193 | 195 | //! render_to(&mut f)
|
194 | 196 | //! }
|
195 | 197 | //! ```
|
|
204 | 206 | //!
|
205 | 207 | //! ```rust
|
206 | 208 | //! use std::borrow::IntoCow;
|
| 209 | +//! use std::io::Write; |
207 | 210 | //! use graphviz as dot;
|
208 | 211 | //!
|
209 | 212 | //! type Nd<'a> = (uint, &'a str);
|
210 | 213 | //! type Ed<'a> = (Nd<'a>, Nd<'a>);
|
211 | 214 | //! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
|
212 | 215 | //!
|
213 |
| -//! pub fn render_to<W:Writer>(output: &mut W) { |
| 216 | +//! pub fn render_to<W: Write>(output: &mut W) { |
214 | 217 | //! let nodes = vec!("{x,y}","{x}","{y}","{}");
|
215 | 218 | //! let edges = vec!((0,1), (0,2), (1,3), (2,3));
|
216 | 219 | //! let graph = Graph { nodes: nodes, edges: edges };
|
|
250 | 253 | //! ```
|
251 | 254 | //!
|
252 | 255 | //! ```no_run
|
253 |
| -//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() } |
| 256 | +//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() } |
254 | 257 | //! pub fn main() {
|
255 |
| -//! use std::old_io::File; |
256 |
| -//! let mut f = File::create(&Path::new("example3.dot")); |
| 258 | +//! use std::fs::File; |
| 259 | +//! let mut f = File::create("example3.dot").unwrap(); |
257 | 260 | //! render_to(&mut f)
|
258 | 261 | //! }
|
259 | 262 | //! ```
|
|
277 | 280 | html_root_url = "http://doc.rust-lang.org/nightly/")]
|
278 | 281 | #![feature(int_uint)]
|
279 | 282 | #![feature(collections)]
|
280 |
| -#![feature(old_io)] |
281 | 283 |
|
282 | 284 | use self::LabelText::*;
|
283 | 285 |
|
284 | 286 | use std::borrow::{IntoCow, Cow};
|
285 |
| -use std::old_io; |
| 287 | +use std::io::prelude::*; |
| 288 | +use std::io; |
286 | 289 |
|
287 | 290 | /// The text for a graphviz label on a node or edge.
|
288 | 291 | pub enum LabelText<'a> {
|
@@ -529,26 +532,26 @@ pub fn default_options() -> Vec<RenderOption> { vec![] }
|
529 | 532 |
|
530 | 533 | /// Renders directed graph `g` into the writer `w` in DOT syntax.
|
531 | 534 | /// (Simple wrapper around `render_opts` that passes a default set of options.)
|
532 |
| -pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>( |
| 535 | +pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>( |
533 | 536 | g: &'a G,
|
534 |
| - w: &mut W) -> old_io::IoResult<()> { |
| 537 | + w: &mut W) -> io::Result<()> { |
535 | 538 | render_opts(g, w, &[])
|
536 | 539 | }
|
537 | 540 |
|
538 | 541 | /// Renders directed graph `g` into the writer `w` in DOT syntax.
|
539 | 542 | /// (Main entry point for the library.)
|
540 |
| -pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>( |
| 543 | +pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>( |
541 | 544 | g: &'a G,
|
542 | 545 | w: &mut W,
|
543 |
| - options: &[RenderOption]) -> old_io::IoResult<()> |
| 546 | + options: &[RenderOption]) -> io::Result<()> |
544 | 547 | {
|
545 |
| - fn writeln<W:Writer>(w: &mut W, arg: &[&str]) -> old_io::IoResult<()> { |
546 |
| - for &s in arg { try!(w.write_str(s)); } |
547 |
| - w.write_char('\n') |
| 548 | + fn writeln<W:Write>(w: &mut W, arg: &[&str]) -> io::Result<()> { |
| 549 | + for &s in arg { try!(w.write_all(s.as_bytes())); } |
| 550 | + write!(w, "\n") |
548 | 551 | }
|
549 | 552 |
|
550 |
| - fn indent<W:Writer>(w: &mut W) -> old_io::IoResult<()> { |
551 |
| - w.write_str(" ") |
| 553 | + fn indent<W:Write>(w: &mut W) -> io::Result<()> { |
| 554 | + w.write_all(b" ") |
552 | 555 | }
|
553 | 556 |
|
554 | 557 | try!(writeln(w, &["digraph ", g.graph_id().as_slice(), " {"]));
|
@@ -589,7 +592,8 @@ mod tests {
|
589 | 592 | use self::NodeLabels::*;
|
590 | 593 | use super::{Id, Labeller, Nodes, Edges, GraphWalk, render};
|
591 | 594 | use super::LabelText::{self, LabelStr, EscStr};
|
592 |
| - use std::old_io::IoResult; |
| 595 | + use std::io; |
| 596 | + use std::io::prelude::*; |
593 | 597 | use std::borrow::IntoCow;
|
594 | 598 | use std::iter::repeat;
|
595 | 599 |
|
@@ -738,10 +742,12 @@ mod tests {
|
738 | 742 | }
|
739 | 743 | }
|
740 | 744 |
|
741 |
| - fn test_input(g: LabelledGraph) -> IoResult<String> { |
| 745 | + fn test_input(g: LabelledGraph) -> io::Result<String> { |
742 | 746 | let mut writer = Vec::new();
|
743 | 747 | render(&g, &mut writer).unwrap();
|
744 |
| - (&mut &*writer).read_to_string() |
| 748 | + let mut s = String::new(); |
| 749 | + try!(Read::read_to_string(&mut &*writer, &mut s)); |
| 750 | + Ok(s) |
745 | 751 | }
|
746 | 752 |
|
747 | 753 | // All of the tests use raw-strings as the format for the expected outputs,
|
@@ -853,9 +859,10 @@ r#"digraph hasse_diagram {
|
853 | 859 | edge(1, 3, ";"), edge(2, 3, ";" )));
|
854 | 860 |
|
855 | 861 | render(&g, &mut writer).unwrap();
|
856 |
| - let r = (&mut &*writer).read_to_string(); |
| 862 | + let mut r = String::new(); |
| 863 | + Read::read_to_string(&mut &*writer, &mut r).unwrap(); |
857 | 864 |
|
858 |
| - assert_eq!(r.unwrap(), |
| 865 | + assert_eq!(r, |
859 | 866 | r#"digraph syntax_tree {
|
860 | 867 | N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"];
|
861 | 868 | N1[label="branch1"];
|
|
0 commit comments