49
49
//! ```rust
50
50
//! #![feature(rustc_private)]
51
51
//!
52
- //! use graphviz::IntoCow;
53
52
//! use std::io::Write;
54
53
//! use graphviz as dot;
55
54
//!
84
83
//! }
85
84
//! nodes.sort();
86
85
//! nodes.dedup();
87
- //! nodes.into_cow ()
86
+ //! nodes.into ()
88
87
//! }
89
88
//!
90
89
//! fn edges(&'a self) -> dot::Edges<'a,Ed> {
91
90
//! let &Edges(ref edges) = self;
92
- //! (&edges[..]).into_cow ()
91
+ //! (&edges[..]).into ()
93
92
//! }
94
93
//!
95
94
//! fn source(&self, e: &Ed) -> Nd { let &(s,_) = e; s }
144
143
//! Since both the set of nodes and the set of edges are always
145
144
//! constructed from scratch via iterators, we use the `collect()` method
146
145
//! from the `Iterator` trait to collect the nodes and edges into freshly
147
- //! constructed growable `Vec` values (rather use the `into_cow`
148
- //! from the `IntoCow` trait as was used in the first example
149
- //! above).
146
+ //! constructed growable `Vec` values (rather than using `Cow` as in the
147
+ //! first example above).
150
148
//!
151
149
//! The output from this example renders four nodes that make up the
152
150
//! Hasse-diagram for the subsets of the set `{x, y}`. Each edge is
293
291
294
292
use self :: LabelText :: * ;
295
293
296
- use std:: borrow:: { Cow , ToOwned } ;
294
+ use std:: borrow:: Cow ;
297
295
use std:: io:: prelude:: * ;
298
296
use std:: io;
299
297
@@ -411,8 +409,8 @@ impl<'a> Id<'a> {
411
409
///
412
410
/// Passing an invalid string (containing spaces, brackets,
413
411
/// quotes, ...) will return an empty `Err` value.
414
- pub fn new < Name : IntoCow < ' a , str > > ( name : Name ) -> Result < Id < ' a > , ( ) > {
415
- let name = name. into_cow ( ) ;
412
+ pub fn new < Name : Into < Cow < ' a , str > > > ( name : Name ) -> Result < Id < ' a > , ( ) > {
413
+ let name = name. into ( ) ;
416
414
match name. chars ( ) . next ( ) {
417
415
Some ( c) if c. is_ascii_alphabetic ( ) || c == '_' => { }
418
416
_ => return Err ( ( ) ) ,
@@ -473,7 +471,7 @@ pub trait Labeller<'a> {
473
471
/// The label need not be unique, and may be the empty string; the
474
472
/// default is in fact the empty string.
475
473
fn edge_label ( & ' a self , _e : & Self :: Edge ) -> LabelText < ' a > {
476
- LabelStr ( "" . into_cow ( ) )
474
+ LabelStr ( "" . into ( ) )
477
475
}
478
476
479
477
/// Maps `n` to a style that will be used in the rendered output.
@@ -497,16 +495,16 @@ pub fn escape_html(s: &str) -> String {
497
495
}
498
496
499
497
impl < ' a > LabelText < ' a > {
500
- pub fn label < S : IntoCow < ' a , str > > ( s : S ) -> LabelText < ' a > {
501
- LabelStr ( s. into_cow ( ) )
498
+ pub fn label < S : Into < Cow < ' a , str > > > ( s : S ) -> LabelText < ' a > {
499
+ LabelStr ( s. into ( ) )
502
500
}
503
501
504
- pub fn escaped < S : IntoCow < ' a , str > > ( s : S ) -> LabelText < ' a > {
505
- EscStr ( s. into_cow ( ) )
502
+ pub fn escaped < S : Into < Cow < ' a , str > > > ( s : S ) -> LabelText < ' a > {
503
+ EscStr ( s. into ( ) )
506
504
}
507
505
508
- pub fn html < S : IntoCow < ' a , str > > ( s : S ) -> LabelText < ' a > {
509
- HtmlStr ( s. into_cow ( ) )
506
+ pub fn html < S : Into < Cow < ' a , str > > > ( s : S ) -> LabelText < ' a > {
507
+ HtmlStr ( s. into ( ) )
510
508
}
511
509
512
510
fn escape_char < F > ( c : char , mut f : F )
@@ -550,7 +548,7 @@ impl<'a> LabelText<'a> {
550
548
EscStr ( s) => s,
551
549
LabelStr ( s) => {
552
550
if s. contains ( '\\' ) {
553
- ( & * s) . escape_default ( ) . into_cow ( )
551
+ ( & * s) . escape_default ( ) . into ( )
554
552
} else {
555
553
s
556
554
}
@@ -570,7 +568,7 @@ impl<'a> LabelText<'a> {
570
568
let suffix = suffix. pre_escaped_content ( ) ;
571
569
prefix. push_str ( r"\n\n" ) ;
572
570
prefix. push_str ( & suffix) ;
573
- EscStr ( prefix. into_cow ( ) )
571
+ EscStr ( prefix. into ( ) )
574
572
}
575
573
}
576
574
@@ -696,48 +694,13 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
696
694
writeln ! ( w, "}}" )
697
695
}
698
696
699
- pub trait IntoCow < ' a , B : ?Sized > where B : ToOwned {
700
- fn into_cow ( self ) -> Cow < ' a , B > ;
701
- }
702
-
703
- impl < ' a > IntoCow < ' a , str > for String {
704
- fn into_cow ( self ) -> Cow < ' a , str > {
705
- Cow :: Owned ( self )
706
- }
707
- }
708
-
709
- impl < ' a > IntoCow < ' a , str > for & ' a str {
710
- fn into_cow ( self ) -> Cow < ' a , str > {
711
- Cow :: Borrowed ( self )
712
- }
713
- }
714
-
715
- impl < ' a > IntoCow < ' a , str > for Cow < ' a , str > {
716
- fn into_cow ( self ) -> Cow < ' a , str > {
717
- self
718
- }
719
- }
720
-
721
- impl < ' a , T : Clone > IntoCow < ' a , [ T ] > for Vec < T > {
722
- fn into_cow ( self ) -> Cow < ' a , [ T ] > {
723
- Cow :: Owned ( self )
724
- }
725
- }
726
-
727
- impl < ' a , T : Clone > IntoCow < ' a , [ T ] > for & ' a [ T ] {
728
- fn into_cow ( self ) -> Cow < ' a , [ T ] > {
729
- Cow :: Borrowed ( self )
730
- }
731
- }
732
-
733
697
#[ cfg( test) ]
734
698
mod tests {
735
699
use self :: NodeLabels :: * ;
736
700
use super :: { Id , Labeller , Nodes , Edges , GraphWalk , render, Style } ;
737
701
use super :: LabelText :: { self , LabelStr , EscStr , HtmlStr } ;
738
702
use std:: io;
739
703
use std:: io:: prelude:: * ;
740
- use IntoCow ;
741
704
742
705
/// each node is an index in a vector in the graph.
743
706
type Node = usize ;
@@ -852,12 +815,12 @@ mod tests {
852
815
}
853
816
fn node_label ( & ' a self , n : & Node ) -> LabelText < ' a > {
854
817
match self . node_labels [ * n] {
855
- Some ( ref l) => LabelStr ( l. into_cow ( ) ) ,
818
+ Some ( l) => LabelStr ( l. into ( ) ) ,
856
819
None => LabelStr ( id_name ( n) . name ( ) ) ,
857
820
}
858
821
}
859
822
fn edge_label ( & ' a self , e : & & ' a Edge ) -> LabelText < ' a > {
860
- LabelStr ( e. label . into_cow ( ) )
823
+ LabelStr ( e. label . into ( ) )
861
824
}
862
825
fn node_style ( & ' a self , n : & Node ) -> Style {
863
826
self . node_styles [ * n]
0 commit comments