@@ -322,20 +322,20 @@ impl Uuid {
322
322
/// Returns the UUID as a string of 16 hexadecimal digits
323
323
///
324
324
/// Example: `936DA01F9ABD4d9d80C702AF85C822A8`
325
- pub fn to_simple_str ( & self ) -> ~ str {
325
+ pub fn to_simple_str ( & self ) -> StrBuf {
326
326
let mut s: Vec < u8 > = Vec :: from_elem ( 32 , 0u8 ) ;
327
327
for i in range ( 0 u, 16 u) {
328
328
let digit = format ! ( "{:02x}" , self . bytes[ i] as uint) ;
329
329
* s. get_mut ( i* 2 +0 ) = digit[ 0 ] ;
330
330
* s. get_mut ( i* 2 +1 ) = digit[ 1 ] ;
331
331
}
332
- str:: from_utf8 ( s. as_slice ( ) ) . unwrap ( ) . to_str ( )
332
+ str:: from_utf8 ( s. as_slice ( ) ) . unwrap ( ) . to_strbuf ( )
333
333
}
334
334
335
335
/// Returns a string of hexadecimal digits, separated into groups with a hyphen.
336
336
///
337
337
/// Example: `550e8400-e29b-41d4-a716-446655440000`
338
- pub fn to_hyphenated_str ( & self ) -> ~ str {
338
+ pub fn to_hyphenated_str ( & self ) -> StrBuf {
339
339
use std:: mem:: { to_be16, to_be32} ;
340
340
// Convert to field-based struct as it matches groups in output.
341
341
// Ensure fields are in network byte order, as per RFC.
@@ -346,8 +346,8 @@ impl Uuid {
346
346
uf. data1 = to_be32 ( uf. data1 ) ;
347
347
uf. data2 = to_be16 ( uf. data2 ) ;
348
348
uf. data3 = to_be16 ( uf. data3 ) ;
349
- let s = format ! ( "{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
350
- {:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
349
+ let s = format_strbuf ! ( "{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
350
+ {:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
351
351
uf. data1,
352
352
uf. data2, uf. data3,
353
353
uf. data4[ 0 ] , uf. data4[ 1 ] ,
@@ -361,8 +361,8 @@ impl Uuid {
361
361
/// This is the same as the hyphenated format, but with the "urn:uuid:" prefix.
362
362
///
363
363
/// Example: `urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4`
364
- pub fn to_urn_str ( & self ) -> ~ str {
365
- "urn:uuid:" + self . to_hyphenated_str ( )
364
+ pub fn to_urn_str ( & self ) -> StrBuf {
365
+ format_strbuf ! ( "urn:uuid:{}" , self . to_hyphenated_str( ) )
366
366
}
367
367
368
368
/// Parses a UUID from a string of hexadecimal digits with optional hyphens
@@ -493,7 +493,7 @@ impl TotalEq for Uuid {}
493
493
impl < T : Encoder < E > , E > Encodable < T , E > for Uuid {
494
494
/// Encode a UUID as a hypenated string
495
495
fn encode ( & self , e : & mut T ) -> Result < ( ) , E > {
496
- e. emit_str ( self . to_hyphenated_str ( ) )
496
+ e. emit_str ( self . to_hyphenated_str ( ) . as_slice ( ) )
497
497
}
498
498
}
499
499
@@ -647,7 +647,7 @@ mod test {
647
647
let s = uuid1. to_simple_str ( ) ;
648
648
649
649
assert ! ( s. len( ) == 32 ) ;
650
- assert ! ( s. chars( ) . all( |c| c. is_digit_radix( 16 ) ) ) ;
650
+ assert ! ( s. as_slice ( ) . chars( ) . all( |c| c. is_digit_radix( 16 ) ) ) ;
651
651
}
652
652
653
653
#[ test]
@@ -656,7 +656,7 @@ mod test {
656
656
let s = uuid1. to_str ( ) ;
657
657
658
658
assert ! ( s. len( ) == 32 ) ;
659
- assert ! ( s. chars( ) . all( |c| c. is_digit_radix( 16 ) ) ) ;
659
+ assert ! ( s. as_slice ( ) . chars( ) . all( |c| c. is_digit_radix( 16 ) ) ) ;
660
660
}
661
661
662
662
#[ test]
@@ -665,18 +665,20 @@ mod test {
665
665
let s = uuid1. to_hyphenated_str ( ) ;
666
666
667
667
assert ! ( s. len( ) == 36 ) ;
668
- assert ! ( s. chars( ) . all( |c| c. is_digit_radix( 16 ) || c == '-' ) ) ;
668
+ assert ! ( s. as_slice ( ) . chars( ) . all( |c| c. is_digit_radix( 16 ) || c == '-' ) ) ;
669
669
}
670
670
671
671
#[ test]
672
672
fn test_to_urn_str ( ) {
673
673
let uuid1 = Uuid :: new_v4 ( ) ;
674
674
let ss = uuid1. to_urn_str ( ) ;
675
- let s = ss. slice ( 9 , ss. len ( ) ) ;
675
+ let s = ss. as_slice ( ) . slice ( 9 , ss. len ( ) ) ;
676
676
677
- assert ! ( ss. starts_with( "urn:uuid:" ) ) ;
677
+ assert ! ( ss. as_slice ( ) . starts_with( "urn:uuid:" ) ) ;
678
678
assert ! ( s. len( ) == 36 ) ;
679
- assert ! ( s. chars( ) . all( |c| c. is_digit_radix( 16 ) || c == '-' ) ) ;
679
+ assert ! ( s. as_slice( )
680
+ . chars( )
681
+ . all( |c| c. is_digit_radix( 16 ) || c == '-' ) ) ;
680
682
}
681
683
682
684
#[ test]
@@ -686,7 +688,8 @@ mod test {
686
688
let hs = uuid1. to_hyphenated_str ( ) ;
687
689
let ss = uuid1. to_str ( ) ;
688
690
689
- let hsn = str:: from_chars ( hs. chars ( )
691
+ let hsn = str:: from_chars ( hs. as_slice ( )
692
+ . chars ( )
690
693
. filter ( |& c| c != '-' )
691
694
. collect :: < Vec < char > > ( )
692
695
. as_slice ( ) ) ;
@@ -699,7 +702,7 @@ mod test {
699
702
let uuid = Uuid :: new_v4 ( ) ;
700
703
701
704
let hs = uuid. to_hyphenated_str ( ) ;
702
- let uuid_hs = Uuid :: parse_string ( hs) . unwrap ( ) ;
705
+ let uuid_hs = Uuid :: parse_string ( hs. as_slice ( ) ) . unwrap ( ) ;
703
706
assert ! ( uuid_hs == uuid) ;
704
707
705
708
let ss = uuid. to_str ( ) ;
@@ -727,7 +730,7 @@ mod test {
727
730
728
731
let u = Uuid :: from_fields ( d1, d2, d3, d4. as_slice ( ) ) ;
729
732
730
- let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8" . to_owned ( ) ;
733
+ let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8" . to_strbuf ( ) ;
731
734
let result = u. to_simple_str ( ) ;
732
735
assert ! ( result == expected) ;
733
736
}
@@ -738,7 +741,7 @@ mod test {
738
741
0xd1 , 0xd2 , 0xd3 , 0xd4 , 0xd5 , 0xd6 , 0xd7 , 0xd8 ) ;
739
742
740
743
let u = Uuid :: from_bytes ( b. as_slice ( ) ) . unwrap ( ) ;
741
- let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8" . to_owned ( ) ;
744
+ let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8" . to_strbuf ( ) ;
742
745
743
746
assert ! ( u. to_simple_str( ) == expected) ;
744
747
}
0 commit comments