@@ -17,7 +17,7 @@ use str::OwnedStr;
1717use container:: Container ;
1818use cast;
1919use iter:: Iterator ;
20- use vec:: { CopyableVector , ImmutableVector , MutableVector } ;
20+ use vec:: { ImmutableVector , MutableVector } ;
2121use to_bytes:: IterBytes ;
2222use option:: { Some , None } ;
2323
@@ -154,10 +154,10 @@ impl AsciiCast<Ascii> for char {
154154
155155/// Trait for copyless casting to an ascii vector.
156156pub trait OwnedAsciiCast {
157- /// Take ownership and cast to an ascii vector without trailing zero element .
157+ /// Take ownership and cast to an ascii vector.
158158 fn into_ascii ( self ) -> ~[ Ascii ] ;
159159
160- /// Take ownership and cast to an ascii vector without trailing zero element .
160+ /// Take ownership and cast to an ascii vector.
161161 /// Does not perform validation checks.
162162 unsafe fn into_ascii_nocheck ( self ) -> ~[ Ascii ] ;
163163}
@@ -188,26 +188,26 @@ impl OwnedAsciiCast for ~str {
188188 }
189189}
190190
191- /// Trait for converting an ascii type to a string. Needed to convert `&[Ascii]` to `~str`
191+ /// Trait for converting an ascii type to a string. Needed to convert
192+ /// `&[Ascii]` to `&str`.
192193pub trait AsciiStr {
193194 /// Convert to a string.
194- fn to_str_ascii ( & self ) -> ~ str ;
195+ fn as_str_ascii < ' a > ( & ' a self ) -> & ' a str ;
195196
196197 /// Convert to vector representing a lower cased ascii string.
197198 fn to_lower ( & self ) -> ~[ Ascii ] ;
198199
199200 /// Convert to vector representing a upper cased ascii string.
200201 fn to_upper ( & self ) -> ~[ Ascii ] ;
201202
202- /// Compares two Ascii strings ignoring case
203+ /// Compares two Ascii strings ignoring case.
203204 fn eq_ignore_case ( self , other : & [ Ascii ] ) -> bool ;
204205}
205206
206207impl < ' self > AsciiStr for & ' self [ Ascii ] {
207208 #[ inline]
208- fn to_str_ascii ( & self ) -> ~str {
209- let cpy = self . to_owned ( ) ;
210- unsafe { cast:: transmute ( cpy) }
209+ fn as_str_ascii < ' a > ( & ' a self ) -> & ' a str {
210+ unsafe { cast:: transmute ( * self ) }
211211 }
212212
213213 #[ inline]
@@ -443,12 +443,12 @@ mod tests {
443443 let v = ~[ 40u8 , 32u8 , 59u8 ] ; assert_eq ! ( v. to_ascii( ) , v2ascii!( [ 40 , 32 , 59 ] ) ) ;
444444 let v = ~"( ; "; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
445445
446- assert_eq!(" abCDef& ?#". to_ascii ( ) . to_lower ( ) . to_str_ascii ( ) , ~"abcdef& ?#") ;
447- assert_eq ! ( "abCDef&?#" . to_ascii( ) . to_upper( ) . to_str_ascii ( ) , ~"ABCDEF & ?#");
446+ assert_eq!(" abCDef& ?#". to_ascii ( ) . to_lower ( ) . into_str ( ) , ~"abcdef& ?#") ;
447+ assert_eq ! ( "abCDef&?#" . to_ascii( ) . to_upper( ) . into_str ( ) , ~"ABCDEF & ?#");
448448
449- assert_eq!(" ".to_ascii().to_lower().to_str_ascii (), ~" ");
450- assert_eq!(" YMCA ".to_ascii().to_lower().to_str_ascii (), ~" ymca");
451- assert_eq!(" abcDEFxyz: . ; ".to_ascii().to_upper().to_str_ascii (), ~" ABCDEFXYZ : . ; ");
449+ assert_eq!(" ".to_ascii().to_lower().into_str (), ~" ");
450+ assert_eq!(" YMCA ".to_ascii().to_lower().into_str (), ~" ymca");
451+ assert_eq!(" abcDEFxyz: . ; ".to_ascii().to_upper().into_str (), ~" ABCDEFXYZ : . ; ");
452452
453453 assert!(" aBcDeF& ?#".to_ascii().eq_ignore_case(" AbCdEf & ?#".to_ascii()));
454454
@@ -465,7 +465,10 @@ mod tests {
465465 }
466466
467467 #[test]
468- fn test_ascii_to_str() { assert_eq!(v2ascii!([40, 32, 59]).to_str_ascii(), ~" ( ; "); }
468+ fn test_ascii_as_str() {
469+ let v = v2ascii!([40, 32, 59]);
470+ assert_eq!(v.as_str_ascii(), " ( ; ");
471+ }
469472
470473 #[test]
471474 fn test_ascii_into_str() {
0 commit comments