File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ impl String {
91
91
Err ( vec)
92
92
}
93
93
}
94
-
94
+
95
95
/// Convert a vector of chars to a string
96
96
///
97
97
/// # Example
@@ -137,6 +137,23 @@ impl String {
137
137
buf
138
138
}
139
139
140
+ /// Convert a byte to a UTF-8 string
141
+ ///
142
+ /// # Failure
143
+ ///
144
+ /// Fails if invalid UTF-8
145
+ ///
146
+ /// # Example
147
+ ///
148
+ /// ```rust
149
+ /// let string = String::from_byte(104);
150
+ /// assert_eq!(string.as_slice(), "h");
151
+ /// ```
152
+ pub fn from_byte ( b : u8 ) -> String {
153
+ assert ! ( b < 128u8 ) ;
154
+ String :: from_char ( 1 , b as char )
155
+ }
156
+
140
157
/// Pushes the given string onto this string buffer.
141
158
#[ inline]
142
159
pub fn push_str ( & mut self , string : & str ) {
Original file line number Diff line number Diff line change 16
16
use std:: * ;
17
17
18
18
fn main ( ) {
19
- str :: from_byte ( 'a' as u8 ) ; // avoid an unused import message
19
+ String :: from_byte ( b 'a') ; // avoid an unused import message
20
20
21
21
fail ! ( "fail works" )
22
22
}
You can’t perform that action at this time.
0 commit comments