54
54
pub use self :: MaybeOwned :: * ;
55
55
use self :: RecompositionState :: * ;
56
56
use self :: DecompositionType :: * ;
57
- use core:: borrow:: { BorrowFrom , ToOwned } ;
57
+ use core:: borrow:: { BorrowFrom , Cow , ToOwned } ;
58
58
use core:: default:: Default ;
59
59
use core:: fmt;
60
60
use core:: cmp;
@@ -67,7 +67,7 @@ use core::prelude::{range};
67
67
68
68
use hash;
69
69
use ring_buf:: RingBuf ;
70
- use string:: { String , ToString } ;
70
+ use string:: String ;
71
71
use unicode;
72
72
use vec:: Vec ;
73
73
@@ -425,22 +425,24 @@ Section: MaybeOwned
425
425
/// A string type that can hold either a `String` or a `&str`.
426
426
/// This can be useful as an optimization when an allocation is sometimes
427
427
/// needed but not always.
428
+ #[ deprecated = "use std::str::CowString" ]
428
429
pub enum MaybeOwned < ' a > {
429
430
/// A borrowed string.
430
431
Slice ( & ' a str ) ,
431
432
/// An owned string.
432
433
Owned ( String )
433
434
}
434
435
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 > ;
437
438
439
+ #[ deprecated = "use std::str::CowString" ]
438
440
impl < ' a > MaybeOwned < ' a > {
439
441
/// Returns `true` if this `MaybeOwned` wraps an owned string.
440
442
///
441
443
/// # Example
442
444
///
443
- /// ```rust
445
+ /// ``` ignore
444
446
/// let string = String::from_str("orange");
445
447
/// let maybe_owned_string = string.into_maybe_owned();
446
448
/// assert_eq!(true, maybe_owned_string.is_owned());
@@ -457,7 +459,7 @@ impl<'a> MaybeOwned<'a> {
457
459
///
458
460
/// # Example
459
461
///
460
- /// ```rust
462
+ /// ``` ignore
461
463
/// let string = "orange";
462
464
/// let maybe_owned_string = string.as_slice().into_maybe_owned();
463
465
/// assert_eq!(true, maybe_owned_string.is_slice());
@@ -475,46 +477,56 @@ impl<'a> MaybeOwned<'a> {
475
477
pub fn len ( & self ) -> uint { self . as_slice ( ) . len ( ) }
476
478
477
479
/// Returns true if the string contains no bytes
480
+ #[ allow( deprecated) ]
478
481
#[ inline]
479
482
pub fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
480
483
}
481
484
485
+ #[ deprecated = "use std::borrow::IntoCow" ]
482
486
/// Trait for moving into a `MaybeOwned`.
483
487
pub trait IntoMaybeOwned < ' a > {
484
488
/// Moves `self` into a `MaybeOwned`.
485
489
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > ;
486
490
}
487
491
492
+ #[ deprecated = "use std::borrow::IntoCow" ]
493
+ #[ allow( deprecated) ]
488
494
impl < ' a > IntoMaybeOwned < ' a > for String {
489
495
/// # Example
490
496
///
491
- /// ```rust
497
+ /// ``` ignore
492
498
/// let owned_string = String::from_str("orange");
493
499
/// let maybe_owned_string = owned_string.into_maybe_owned();
494
500
/// assert_eq!(true, maybe_owned_string.is_owned());
495
501
/// ```
502
+ #[ allow( deprecated) ]
496
503
#[ inline]
497
504
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > {
498
505
Owned ( self )
499
506
}
500
507
}
501
508
509
+ #[ deprecated = "use std::borrow::IntoCow" ]
510
+ #[ allow( deprecated) ]
502
511
impl < ' a > IntoMaybeOwned < ' a > for & ' a str {
503
512
/// # Example
504
513
///
505
- /// ```rust
514
+ /// ``` ignore
506
515
/// let string = "orange";
507
516
/// let maybe_owned_str = string.as_slice().into_maybe_owned();
508
517
/// assert_eq!(false, maybe_owned_str.is_owned());
509
518
/// ```
519
+ #[ allow( deprecated) ]
510
520
#[ inline]
511
521
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { Slice ( self ) }
512
522
}
513
523
524
+ #[ allow( deprecated) ]
525
+ #[ deprecated = "use std::borrow::IntoCow" ]
514
526
impl < ' a > IntoMaybeOwned < ' a > for MaybeOwned < ' a > {
515
527
/// # Example
516
528
///
517
- /// ```rust
529
+ /// ``` ignore
518
530
/// let str = "orange";
519
531
/// let maybe_owned_str = str.as_slice().into_maybe_owned();
520
532
/// let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
@@ -524,37 +536,44 @@ impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> {
524
536
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { self }
525
537
}
526
538
539
+ #[ deprecated = "use std::str::CowString" ]
527
540
impl < ' a > PartialEq for MaybeOwned < ' a > {
528
541
#[ inline]
529
542
fn eq ( & self , other : & MaybeOwned ) -> bool {
530
543
self . as_slice ( ) == other. as_slice ( )
531
544
}
532
545
}
533
546
547
+ #[ deprecated = "use std::str::CowString" ]
534
548
impl < ' a > Eq for MaybeOwned < ' a > { }
535
549
550
+ #[ deprecated = "use std::str::CowString" ]
536
551
impl < ' a > PartialOrd for MaybeOwned < ' a > {
537
552
#[ inline]
538
553
fn partial_cmp ( & self , other : & MaybeOwned ) -> Option < Ordering > {
539
554
Some ( self . cmp ( other) )
540
555
}
541
556
}
542
557
558
+ #[ deprecated = "use std::str::CowString" ]
543
559
impl < ' a > Ord for MaybeOwned < ' a > {
544
560
#[ inline]
545
561
fn cmp ( & self , other : & MaybeOwned ) -> Ordering {
546
562
self . as_slice ( ) . cmp ( other. as_slice ( ) )
547
563
}
548
564
}
549
565
566
+ #[ deprecated = "use std::str::CowString" ]
550
567
impl < ' a , S : Str > Equiv < S > for MaybeOwned < ' a > {
551
568
#[ inline]
552
569
fn equiv ( & self , other : & S ) -> bool {
553
570
self . as_slice ( ) == other. as_slice ( )
554
571
}
555
572
}
556
573
574
+ #[ deprecated = "use std::str::CowString" ]
557
575
impl < ' a > Str for MaybeOwned < ' a > {
576
+ #[ allow( deprecated) ]
558
577
#[ inline]
559
578
fn as_slice < ' b > ( & ' b self ) -> & ' b str {
560
579
match * self {
@@ -564,7 +583,9 @@ impl<'a> Str for MaybeOwned<'a> {
564
583
}
565
584
}
566
585
586
+ #[ deprecated = "use std::str::CowString" ]
567
587
impl < ' a > StrAllocating for MaybeOwned < ' a > {
588
+ #[ allow( deprecated) ]
568
589
#[ inline]
569
590
fn into_string ( self ) -> String {
570
591
match self {
@@ -574,7 +595,9 @@ impl<'a> StrAllocating for MaybeOwned<'a> {
574
595
}
575
596
}
576
597
598
+ #[ deprecated = "use std::str::CowString" ]
577
599
impl < ' a > Clone for MaybeOwned < ' a > {
600
+ #[ allow( deprecated) ]
578
601
#[ inline]
579
602
fn clone ( & self ) -> MaybeOwned < ' a > {
580
603
match * self {
@@ -584,18 +607,22 @@ impl<'a> Clone for MaybeOwned<'a> {
584
607
}
585
608
}
586
609
610
+ #[ deprecated = "use std::str::CowString" ]
587
611
impl < ' a > Default for MaybeOwned < ' a > {
612
+ #[ allow( deprecated) ]
588
613
#[ inline]
589
614
fn default ( ) -> MaybeOwned < ' a > { Slice ( "" ) }
590
615
}
591
616
617
+ #[ deprecated = "use std::str::CowString" ]
592
618
impl < ' a , H : hash:: Writer > hash:: Hash < H > for MaybeOwned < ' a > {
593
619
#[ inline]
594
620
fn hash ( & self , hasher : & mut H ) {
595
621
self . as_slice ( ) . hash ( hasher)
596
622
}
597
623
}
598
624
625
+ #[ deprecated = "use std::str::CowString" ]
599
626
impl < ' a > fmt:: Show for MaybeOwned < ' a > {
600
627
#[ inline]
601
628
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -613,7 +640,7 @@ impl BorrowFrom<String> for str {
613
640
614
641
#[ unstable = "trait is unstable" ]
615
642
impl ToOwned < String > for str {
616
- fn to_owned ( & self ) -> String { self . to_string ( ) }
643
+ fn to_owned ( & self ) -> String { self . into_string ( ) }
617
644
}
618
645
619
646
/// Unsafe string operations.
@@ -622,6 +649,13 @@ pub mod raw {
622
649
pub use core:: str:: raw:: { slice_unchecked} ;
623
650
}
624
651
652
+ /*
653
+ Section: CowString
654
+ */
655
+
656
+ /// A clone-on-write string
657
+ pub type CowString < ' a > = Cow < ' a , String , str > ;
658
+
625
659
/*
626
660
Section: Trait implementations
627
661
*/
0 commit comments