File tree 4 files changed +7
-8
lines changed
4 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ See the original [`xid`] project for more details.
22
22
## Usage
23
23
24
24
``` rust
25
- println! (" {}" , xid :: new (). to_string () ); // => bva9lbqn1bt68k8mj62g
25
+ println! (" {}" , xid :: new ()); // => bva9lbqn1bt68k8mj62g
26
26
```
27
27
28
28
## Examples
Original file line number Diff line number Diff line change 1
1
fn main ( ) {
2
- println ! ( "{}" , xid:: new( ) . to_string ( ) ) ;
2
+ println ! ( "{}" , xid:: new( ) ) ;
3
3
}
Original file line number Diff line number Diff line change 1
1
use std:: {
2
+ fmt,
2
3
str:: { self , FromStr } ,
3
- string:: ToString ,
4
4
time:: { Duration , SystemTime , UNIX_EPOCH } ,
5
5
} ;
6
6
@@ -54,10 +54,9 @@ impl Id {
54
54
}
55
55
}
56
56
57
- impl ToString for Id {
57
+ impl fmt :: Display for Id {
58
58
// https://github.com/rs/xid/blob/efa678f304ab65d6d57eedcb086798381ae22206/id.go#L208
59
- /// Returns the string representation of the id.
60
- fn to_string ( & self ) -> String {
59
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
61
60
let Self ( raw) = self ;
62
61
let mut bs = [ 0_u8 ; ENCODED_LEN ] ;
63
62
bs[ 19 ] = ENC [ ( ( raw[ 11 ] << 4 ) & 31 ) as usize ] ;
@@ -80,7 +79,7 @@ impl ToString for Id {
80
79
bs[ 2 ] = ENC [ ( ( raw[ 1 ] >> 1 ) & 31 ) as usize ] ;
81
80
bs[ 1 ] = ENC [ ( ( ( raw[ 1 ] >> 6 ) | ( raw[ 0 ] << 2 ) ) & 31 ) as usize ] ;
82
81
bs[ 0 ] = ENC [ ( raw[ 0 ] >> 3 ) as usize ] ;
83
- str:: from_utf8 ( & bs) . unwrap ( ) . to_string ( )
82
+ write ! ( f , "{}" , str :: from_utf8( & bs) . expect ( "valid utf8" ) )
84
83
}
85
84
}
86
85
Original file line number Diff line number Diff line change 19
19
//! ## Usage
20
20
//!
21
21
//! ```
22
- //! println!("{}", xid::new().to_string() ); //=> bva9lbqn1bt68k8mj62g
22
+ //! println!("{}", xid::new()); //=> bva9lbqn1bt68k8mj62g
23
23
//! ```
24
24
//!
25
25
//! [`xid`]: https://github.com/rs/xid
You can’t perform that action at this time.
0 commit comments