summaryrefslogtreecommitdiff
path: root/src/libgraphviz
diff options
context:
space:
mode:
authorljedrz <ljedrz@gmail.com>2018-10-05 14:16:10 +0200
committerljedrz <ljedrz@gmail.com>2018-10-05 14:16:10 +0200
commitc30ce35705d283381f08374234c92a52a27885db (patch)
tree64d64b43f27f75b2e5b728c0e8eb02c503b9650e /src/libgraphviz
parentb8bea5a0a6aef3966008787a25949344f8cf6942 (diff)
downloadrust-c30ce35705d283381f08374234c92a52a27885db.tar.gz
Remove graphviz::IntoCow
Diffstat (limited to 'src/libgraphviz')
-rw-r--r--src/libgraphviz/lib.rs73
1 files changed, 18 insertions, 55 deletions
diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs
index 7acadc32048..396b0366074 100644
--- a/src/libgraphviz/lib.rs
+++ b/src/libgraphviz/lib.rs
@@ -49,7 +49,6 @@
//! ```rust
//! #![feature(rustc_private)]
//!
-//! use graphviz::IntoCow;
//! use std::io::Write;
//! use graphviz as dot;
//!
@@ -84,12 +83,12 @@
//! }
//! nodes.sort();
//! nodes.dedup();
-//! nodes.into_cow()
+//! nodes.into()
//! }
//!
//! fn edges(&'a self) -> dot::Edges<'a,Ed> {
//! let &Edges(ref edges) = self;
-//! (&edges[..]).into_cow()
+//! (&edges[..]).into()
//! }
//!
//! fn source(&self, e: &Ed) -> Nd { let &(s,_) = e; s }
@@ -144,9 +143,8 @@
//! Since both the set of nodes and the set of edges are always
//! constructed from scratch via iterators, we use the `collect()` method
//! from the `Iterator` trait to collect the nodes and edges into freshly
-//! constructed growable `Vec` values (rather use the `into_cow`
-//! from the `IntoCow` trait as was used in the first example
-//! above).
+//! constructed growable `Vec` values (rather than using `Cow` as in the
+//! first example above).
//!
//! The output from this example renders four nodes that make up the
//! Hasse-diagram for the subsets of the set `{x, y}`. Each edge is
@@ -293,7 +291,7 @@
use self::LabelText::*;
-use std::borrow::{Cow, ToOwned};
+use std::borrow::Cow;
use std::io::prelude::*;
use std::io;
@@ -411,8 +409,8 @@ impl<'a> Id<'a> {
///
/// Passing an invalid string (containing spaces, brackets,
/// quotes, ...) will return an empty `Err` value.
- pub fn new<Name: IntoCow<'a, str>>(name: Name) -> Result<Id<'a>, ()> {
- let name = name.into_cow();
+ pub fn new<Name: Into<Cow<'a, str>>>(name: Name) -> Result<Id<'a>, ()> {
+ let name = name.into();
match name.chars().next() {
Some(c) if c.is_ascii_alphabetic() || c == '_' => {}
_ => return Err(()),
@@ -473,7 +471,7 @@ pub trait Labeller<'a> {
/// The label need not be unique, and may be the empty string; the
/// default is in fact the empty string.
fn edge_label(&'a self, _e: &Self::Edge) -> LabelText<'a> {
- LabelStr("".into_cow())
+ LabelStr("".into())
}
/// Maps `n` to a style that will be used in the rendered output.
@@ -497,16 +495,16 @@ pub fn escape_html(s: &str) -> String {
}
impl<'a> LabelText<'a> {
- pub fn label<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
- LabelStr(s.into_cow())
+ pub fn label<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
+ LabelStr(s.into())
}
- pub fn escaped<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
- EscStr(s.into_cow())
+ pub fn escaped<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
+ EscStr(s.into())
}
- pub fn html<S: IntoCow<'a, str>>(s: S) -> LabelText<'a> {
- HtmlStr(s.into_cow())
+ pub fn html<S: Into<Cow<'a, str>>>(s: S) -> LabelText<'a> {
+ HtmlStr(s.into())
}
fn escape_char<F>(c: char, mut f: F)
@@ -550,7 +548,7 @@ impl<'a> LabelText<'a> {
EscStr(s) => s,
LabelStr(s) => {
if s.contains('\\') {
- (&*s).escape_default().into_cow()
+ (&*s).escape_default().into()
} else {
s
}
@@ -570,7 +568,7 @@ impl<'a> LabelText<'a> {
let suffix = suffix.pre_escaped_content();
prefix.push_str(r"\n\n");
prefix.push_str(&suffix);
- EscStr(prefix.into_cow())
+ EscStr(prefix.into())
}
}
@@ -696,40 +694,6 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
writeln!(w, "}}")
}
-pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
- fn into_cow(self) -> Cow<'a, B>;
-}
-
-impl<'a> IntoCow<'a, str> for String {
- fn into_cow(self) -> Cow<'a, str> {
- Cow::Owned(self)
- }
-}
-
-impl<'a> IntoCow<'a, str> for &'a str {
- fn into_cow(self) -> Cow<'a, str> {
- Cow::Borrowed(self)
- }
-}
-
-impl<'a> IntoCow<'a, str> for Cow<'a, str> {
- fn into_cow(self) -> Cow<'a, str> {
- self
- }
-}
-
-impl<'a, T: Clone> IntoCow<'a, [T]> for Vec<T> {
- fn into_cow(self) -> Cow<'a, [T]> {
- Cow::Owned(self)
- }
-}
-
-impl<'a, T: Clone> IntoCow<'a, [T]> for &'a [T] {
- fn into_cow(self) -> Cow<'a, [T]> {
- Cow::Borrowed(self)
- }
-}
-
#[cfg(test)]
mod tests {
use self::NodeLabels::*;
@@ -737,7 +701,6 @@ mod tests {
use super::LabelText::{self, LabelStr, EscStr, HtmlStr};
use std::io;
use std::io::prelude::*;
- use IntoCow;
/// each node is an index in a vector in the graph.
type Node = usize;
@@ -852,12 +815,12 @@ mod tests {
}
fn node_label(&'a self, n: &Node) -> LabelText<'a> {
match self.node_labels[*n] {
- Some(ref l) => LabelStr(l.into_cow()),
+ Some(l) => LabelStr(l.into()),
None => LabelStr(id_name(n).name()),
}
}
fn edge_label(&'a self, e: &&'a Edge) -> LabelText<'a> {
- LabelStr(e.label.into_cow())
+ LabelStr(e.label.into())
}
fn node_style(&'a self, n: &Node) -> Style {
self.node_styles[*n]