File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,35 @@ impl AsRef<str> for AsciiStr {
198
198
}
199
199
}
200
200
201
+ impl < ' a > From < & ' a [ Ascii ] > for & ' a AsciiStr {
202
+ fn from ( slice : & [ Ascii ] ) -> & AsciiStr {
203
+ unsafe { mem:: transmute ( slice) }
204
+ }
205
+ }
206
+ impl From < Box < [ Ascii ] > > for Box < AsciiStr > {
207
+ fn from ( owned : Box < [ Ascii ] > ) -> Box < AsciiStr > {
208
+ unsafe { mem:: transmute ( owned) }
209
+ }
210
+ }
211
+
212
+ macro_rules! impl_into {
213
+ ( $wider: ty) => {
214
+ impl <' a> From <& ' a AsciiStr > for & ' a$wider {
215
+ fn from( slice: & AsciiStr ) -> & $wider {
216
+ unsafe { mem:: transmute( slice) }
217
+ }
218
+ }
219
+ impl From <Box <AsciiStr >> for Box <$wider> {
220
+ fn from( owned: Box <AsciiStr >) -> Box <$wider> {
221
+ unsafe { mem:: transmute( owned) }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ impl_into ! { [ Ascii ] }
227
+ impl_into ! { [ u8 ] }
228
+ impl_into ! { str }
229
+
201
230
impl fmt:: Display for AsciiStr {
202
231
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
203
232
fmt:: Display :: fmt ( self . as_str ( ) , f)
You can’t perform that action at this time.
0 commit comments