5454pub use self :: MaybeOwned :: * ;
5555use self :: RecompositionState :: * ;
5656use self :: DecompositionType :: * ;
57- use core:: borrow:: { BorrowFrom , ToOwned } ;
57+ use core:: borrow:: { BorrowFrom , Cow , ToOwned } ;
5858use core:: default:: Default ;
5959use core:: fmt;
6060use core:: cmp;
@@ -67,7 +67,7 @@ use core::prelude::{range};
6767
6868use hash;
6969use ring_buf:: RingBuf ;
70- use string:: { String , ToString } ;
70+ use string:: String ;
7171use unicode;
7272use vec:: Vec ;
7373
@@ -425,22 +425,24 @@ Section: MaybeOwned
425425/// A string type that can hold either a `String` or a `&str`.
426426/// This can be useful as an optimization when an allocation is sometimes
427427/// needed but not always.
428+ #[ deprecated = "use std::str::CowString" ]
428429pub enum MaybeOwned < ' a > {
429430 /// A borrowed string.
430431 Slice ( & ' a str ) ,
431432 /// An owned string.
432433 Owned ( String )
433434}
434435
435- /// A specialization of `MaybeOwned ` to be sendable.
436- pub type SendStr = MaybeOwned < ' static > ;
436+ /// A specialization of `CowString ` to be sendable.
437+ pub type SendStr = CowString < ' static > ;
437438
439+ #[ deprecated = "use std::str::CowString" ]
438440impl < ' a > MaybeOwned < ' a > {
439441 /// Returns `true` if this `MaybeOwned` wraps an owned string.
440442 ///
441443 /// # Example
442444 ///
443- /// ```rust
445+ /// ``` ignore
444446 /// let string = String::from_str("orange");
445447 /// let maybe_owned_string = string.into_maybe_owned();
446448 /// assert_eq!(true, maybe_owned_string.is_owned());
@@ -457,7 +459,7 @@ impl<'a> MaybeOwned<'a> {
457459 ///
458460 /// # Example
459461 ///
460- /// ```rust
462+ /// ``` ignore
461463 /// let string = "orange";
462464 /// let maybe_owned_string = string.as_slice().into_maybe_owned();
463465 /// assert_eq!(true, maybe_owned_string.is_slice());
@@ -475,46 +477,56 @@ impl<'a> MaybeOwned<'a> {
475477 pub fn len ( & self ) -> uint { self . as_slice ( ) . len ( ) }
476478
477479 /// Returns true if the string contains no bytes
480+ #[ allow( deprecated) ]
478481 #[ inline]
479482 pub fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
480483}
481484
485+ #[ deprecated = "use std::borrow::IntoCow" ]
482486/// Trait for moving into a `MaybeOwned`.
483487pub trait IntoMaybeOwned < ' a > {
484488 /// Moves `self` into a `MaybeOwned`.
485489 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > ;
486490}
487491
492+ #[ deprecated = "use std::borrow::IntoCow" ]
493+ #[ allow( deprecated) ]
488494impl < ' a > IntoMaybeOwned < ' a > for String {
489495 /// # Example
490496 ///
491- /// ```rust
497+ /// ``` ignore
492498 /// let owned_string = String::from_str("orange");
493499 /// let maybe_owned_string = owned_string.into_maybe_owned();
494500 /// assert_eq!(true, maybe_owned_string.is_owned());
495501 /// ```
502+ #[ allow( deprecated) ]
496503 #[ inline]
497504 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > {
498505 Owned ( self )
499506 }
500507}
501508
509+ #[ deprecated = "use std::borrow::IntoCow" ]
510+ #[ allow( deprecated) ]
502511impl < ' a > IntoMaybeOwned < ' a > for & ' a str {
503512 /// # Example
504513 ///
505- /// ```rust
514+ /// ``` ignore
506515 /// let string = "orange";
507516 /// let maybe_owned_str = string.as_slice().into_maybe_owned();
508517 /// assert_eq!(false, maybe_owned_str.is_owned());
509518 /// ```
519+ #[ allow( deprecated) ]
510520 #[ inline]
511521 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { Slice ( self ) }
512522}
513523
524+ #[ allow( deprecated) ]
525+ #[ deprecated = "use std::borrow::IntoCow" ]
514526impl < ' a > IntoMaybeOwned < ' a > for MaybeOwned < ' a > {
515527 /// # Example
516528 ///
517- /// ```rust
529+ /// ``` ignore
518530 /// let str = "orange";
519531 /// let maybe_owned_str = str.as_slice().into_maybe_owned();
520532 /// let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
@@ -524,37 +536,44 @@ impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> {
524536 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { self }
525537}
526538
539+ #[ deprecated = "use std::str::CowString" ]
527540impl < ' a > PartialEq for MaybeOwned < ' a > {
528541 #[ inline]
529542 fn eq ( & self , other : & MaybeOwned ) -> bool {
530543 self . as_slice ( ) == other. as_slice ( )
531544 }
532545}
533546
547+ #[ deprecated = "use std::str::CowString" ]
534548impl < ' a > Eq for MaybeOwned < ' a > { }
535549
550+ #[ deprecated = "use std::str::CowString" ]
536551impl < ' a > PartialOrd for MaybeOwned < ' a > {
537552 #[ inline]
538553 fn partial_cmp ( & self , other : & MaybeOwned ) -> Option < Ordering > {
539554 Some ( self . cmp ( other) )
540555 }
541556}
542557
558+ #[ deprecated = "use std::str::CowString" ]
543559impl < ' a > Ord for MaybeOwned < ' a > {
544560 #[ inline]
545561 fn cmp ( & self , other : & MaybeOwned ) -> Ordering {
546562 self . as_slice ( ) . cmp ( other. as_slice ( ) )
547563 }
548564}
549565
566+ #[ deprecated = "use std::str::CowString" ]
550567impl < ' a , S : Str > Equiv < S > for MaybeOwned < ' a > {
551568 #[ inline]
552569 fn equiv ( & self , other : & S ) -> bool {
553570 self . as_slice ( ) == other. as_slice ( )
554571 }
555572}
556573
574+ #[ deprecated = "use std::str::CowString" ]
557575impl < ' a > Str for MaybeOwned < ' a > {
576+ #[ allow( deprecated) ]
558577 #[ inline]
559578 fn as_slice < ' b > ( & ' b self ) -> & ' b str {
560579 match * self {
@@ -564,7 +583,9 @@ impl<'a> Str for MaybeOwned<'a> {
564583 }
565584}
566585
586+ #[ deprecated = "use std::str::CowString" ]
567587impl < ' a > StrAllocating for MaybeOwned < ' a > {
588+ #[ allow( deprecated) ]
568589 #[ inline]
569590 fn into_string ( self ) -> String {
570591 match self {
@@ -574,7 +595,9 @@ impl<'a> StrAllocating for MaybeOwned<'a> {
574595 }
575596}
576597
598+ #[ deprecated = "use std::str::CowString" ]
577599impl < ' a > Clone for MaybeOwned < ' a > {
600+ #[ allow( deprecated) ]
578601 #[ inline]
579602 fn clone ( & self ) -> MaybeOwned < ' a > {
580603 match * self {
@@ -584,18 +607,22 @@ impl<'a> Clone for MaybeOwned<'a> {
584607 }
585608}
586609
610+ #[ deprecated = "use std::str::CowString" ]
587611impl < ' a > Default for MaybeOwned < ' a > {
612+ #[ allow( deprecated) ]
588613 #[ inline]
589614 fn default ( ) -> MaybeOwned < ' a > { Slice ( "" ) }
590615}
591616
617+ #[ deprecated = "use std::str::CowString" ]
592618impl < ' a , H : hash:: Writer > hash:: Hash < H > for MaybeOwned < ' a > {
593619 #[ inline]
594620 fn hash ( & self , hasher : & mut H ) {
595621 self . as_slice ( ) . hash ( hasher)
596622 }
597623}
598624
625+ #[ deprecated = "use std::str::CowString" ]
599626impl < ' a > fmt:: Show for MaybeOwned < ' a > {
600627 #[ inline]
601628 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -613,7 +640,7 @@ impl BorrowFrom<String> for str {
613640
614641#[ unstable = "trait is unstable" ]
615642impl ToOwned < String > for str {
616- fn to_owned ( & self ) -> String { self . to_string ( ) }
643+ fn to_owned ( & self ) -> String { self . into_string ( ) }
617644}
618645
619646/// Unsafe string operations.
@@ -622,6 +649,13 @@ pub mod raw {
622649 pub use core:: str:: raw:: { slice_unchecked} ;
623650}
624651
652+ /*
653+ Section: CowString
654+ */
655+
656+ /// A clone-on-write string
657+ pub type CowString < ' a > = Cow < ' a , String , str > ;
658+
625659/*
626660Section: Trait implementations
627661*/
0 commit comments