Skip to content

Commit b0b9722

Browse files
committed
---
yaml --- r: 113901 b: refs/heads/master c: c39b1cb h: refs/heads/master i: 113899: 28c0200 v: v3
1 parent 54a745b commit b0b9722

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 418f197351fbc570a0e7bbf93d509cd44f988467
2+
refs/heads/master: c39b1cb1bed78d989b1011f54f6febb7e9e46d94
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/libgraphviz/lib.rs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ type Nd = int;
5454
type Ed = (int,int);
5555
struct Edges(Vec<Ed>);
5656
57-
pub fn main() {
58-
use std::io::File;
57+
pub fn render_to<W:Writer>(output: &mut W) {
5958
let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
60-
let mut f = File::create(&Path::new("example1.dot"));
61-
dot::render(&edges, &mut f).unwrap()
59+
dot::render(&edges, output).unwrap()
6260
}
6361
6462
impl<'a> dot::Labeller<'a, Nd, Ed> for Edges {
@@ -91,6 +89,17 @@ impl<'a> dot::GraphWalk<'a, Nd, Ed> for Edges {
9189
9290
fn target(&self, e: &Ed) -> Nd { let &(_,t) = e; t }
9391
}
92+
93+
# pub fn main() { use std::io::MemWriter; render_to(&mut MemWriter::new()) }
94+
```
95+
96+
```no_run
97+
# pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
98+
pub fn main() {
99+
use std::io::File;
100+
let mut f = File::create(&Path::new("example1.dot"));
101+
render_to(&mut f)
102+
}
94103
```
95104
96105
Output from first example (in `example1.dot`):
@@ -140,19 +149,17 @@ entity `&sube`).
140149
```rust
141150
use dot = graphviz;
142151
use std::str;
143-
use std::io::File;
144152
145153
type Nd = uint;
146154
type Ed<'a> = &'a (uint, uint);
147155
struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
148156
149-
pub fn main() {
157+
pub fn render_to<W:Writer>(output: &mut W) {
150158
let nodes = vec!("{x,y}","{x}","{y}","{}");
151159
let edges = vec!((0,1), (0,2), (1,3), (2,3));
152160
let graph = Graph { nodes: nodes, edges: edges };
153161
154-
let mut f = File::create(&Path::new("example2.dot"));
155-
dot::render(&graph, &mut f).unwrap()
162+
dot::render(&graph, output).unwrap()
156163
}
157164
158165
impl<'a> dot::Labeller<'a, Nd, Ed<'a>> for Graph {
@@ -174,6 +181,17 @@ impl<'a> dot::GraphWalk<'a, Nd, Ed<'a>> for Graph {
174181
fn source(&self, e: &Ed) -> Nd { let & &(s,_) = e; s }
175182
fn target(&self, e: &Ed) -> Nd { let & &(_,t) = e; t }
176183
}
184+
185+
# pub fn main() { use std::io::MemWriter; render_to(&mut MemWriter::new()) }
186+
```
187+
188+
```no_run
189+
# pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
190+
pub fn main() {
191+
use std::io::File;
192+
let mut f = File::create(&Path::new("example2.dot"));
193+
render_to(&mut f)
194+
}
177195
```
178196
179197
The third example is similar to the second, except now each node and
@@ -187,19 +205,17 @@ Hasse-diagram for the subsets of the set `{x, y}`.
187205
```rust
188206
use dot = graphviz;
189207
use std::str;
190-
use std::io::File;
191208
192209
type Nd<'a> = (uint, &'a str);
193210
type Ed<'a> = (Nd<'a>, Nd<'a>);
194211
struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
195212
196-
pub fn main() {
213+
pub fn render_to<W:Writer>(output: &mut W) {
197214
let nodes = vec!("{x,y}","{x}","{y}","{}");
198215
let edges = vec!((0,1), (0,2), (1,3), (2,3));
199216
let graph = Graph { nodes: nodes, edges: edges };
200217
201-
let mut f = File::create(&Path::new("example3.dot"));
202-
dot::render(&graph, &mut f).unwrap()
218+
dot::render(&graph, output).unwrap()
203219
}
204220
205221
impl<'a> dot::Labeller<'a, Nd<'a>, Ed<'a>> for Graph {
@@ -229,6 +245,17 @@ impl<'a> dot::GraphWalk<'a, Nd<'a>, Ed<'a>> for Graph {
229245
fn source(&self, e: &Ed<'a>) -> Nd<'a> { let &(s,_) = e; s }
230246
fn target(&self, e: &Ed<'a>) -> Nd<'a> { let &(_,t) = e; t }
231247
}
248+
249+
# pub fn main() { use std::io::MemWriter; render_to(&mut MemWriter::new()) }
250+
```
251+
252+
```no_run
253+
# pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
254+
pub fn main() {
255+
use std::io::File;
256+
let mut f = File::create(&Path::new("example3.dot"));
257+
render_to(&mut f)
258+
}
232259
```
233260
234261
# References

0 commit comments

Comments
 (0)