File tree Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -39,3 +39,5 @@ in a controlled repository now.
39
39
* ` setimpl.rs ` : example implementation of ` HashSet ` as ` HashMap `
40
40
* ` rng/ ` : example use of ` rand ` crate
41
41
* ` charcast.rs ` : character / number casting examples
42
+ * ` lower.rs ` : boring character lowercase example
43
+ * ` stringchars.rs ` : string ←→ chars conversion examples
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ fn main() {
8
8
println ! ( "{:016x}" , '🦀' as u64 ) ;
9
9
10
10
println ! ( "{}" , 0x78u8 as char ) ;
11
+ // println!("{}", 0x1f980u32 as char); // Nope.
11
12
}
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let s: String = 'ß' . to_uppercase ( ) . collect ( ) ;
3
+ println ! ( "{}" , s) ;
4
+ }
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let s = "🦀hello" ;
3
+ println ! ( "nbytes {}" , s. len( ) ) ;
4
+ println ! ( "nchar {}" , s. chars( ) . count( ) ) ;
5
+ println ! ( "{}" , s. chars( ) . nth( 0 ) . unwrap( ) ) ;
6
+ let t: String = s. chars ( ) . take ( 5 ) . collect ( ) ;
7
+ println ! ( "{}" , t) ;
8
+ let u = s. as_bytes ( ) ;
9
+ println ! ( "{:02x?}" , u) ;
10
+ let v = std:: str:: from_utf8 ( u) . unwrap ( ) ;
11
+ println ! ( "{}" , v) ;
12
+ let v = unsafe { std:: str:: from_utf8_unchecked ( u) } ;
13
+ println ! ( "{}" , v) ;
14
+ let mut w = u. to_vec ( ) ;
15
+ w[ 0 ] = 0 ;
16
+ println ! ( "{}" , unsafe { std:: str :: from_utf8_unchecked( & w) } ) ;
17
+ }
You can’t perform that action at this time.
0 commit comments