File tree Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -559,7 +559,7 @@ pub mod raw {
559
559
use core:: raw:: Slice ;
560
560
use core:: ptr:: RawPtr ;
561
561
562
- use string:: String ;
562
+ use string:: { mod , String } ;
563
563
use vec:: Vec ;
564
564
565
565
pub use core:: str:: raw:: { from_utf8, c_str_to_static_slice, slice_bytes} ;
@@ -590,11 +590,10 @@ pub mod raw {
590
590
buf
591
591
}
592
592
593
- /// Converts an owned vector of bytes to a new owned string. This assumes
594
- /// that the utf-8-ness of the vector has already been validated
595
- #[ inline]
593
+ /// Deprecated. Replaced by `string::raw::from_utf8`
594
+ #[ deprecated = "Use string::raw::from_utf8" ]
596
595
pub unsafe fn from_utf8_owned ( v : Vec < u8 > ) -> String {
597
- mem :: transmute ( v)
596
+ string :: raw :: from_utf8 ( v)
598
597
}
599
598
600
599
/// Converts a byte to a string.
Original file line number Diff line number Diff line change @@ -570,6 +570,19 @@ impl<S: Str> Add<S, String> for String {
570
570
}
571
571
}
572
572
573
+ pub mod raw {
574
+ use super :: String ;
575
+ use vec:: Vec ;
576
+
577
+ /// Converts a vector of bytes to a new `String` without checking if
578
+ /// it contains valid UTF-8. This is unsafe because it assumes that
579
+ /// the utf-8-ness of the vector has already been validated.
580
+ #[ inline]
581
+ pub unsafe fn from_utf8 ( bytes : Vec < u8 > ) -> String {
582
+ String { vec : bytes }
583
+ }
584
+ }
585
+
573
586
#[ cfg( test) ]
574
587
mod tests {
575
588
use std:: prelude:: * ;
Original file line number Diff line number Diff line change 11
11
// ignore-lexer-test FIXME #15679
12
12
13
13
//! Base64 binary-to-text encoding
14
- use std:: str;
15
14
use std:: fmt;
15
+ use std:: string;
16
16
17
17
/// Available encoding character sets
18
18
pub enum CharacterSet {
@@ -148,7 +148,7 @@ impl<'a> ToBase64 for &'a [u8] {
148
148
}
149
149
150
150
unsafe {
151
- str :: raw:: from_utf8_owned ( v)
151
+ string :: raw:: from_utf8 ( v)
152
152
}
153
153
}
154
154
}
Original file line number Diff line number Diff line change 11
11
// ignore-lexer-test FIXME #15679
12
12
13
13
//! Hex binary-to-text encoding
14
- use std:: str;
15
14
use std:: fmt;
15
+ use std:: string;
16
16
17
17
/// A trait for converting a value to hexadecimal encoding
18
18
pub trait ToHex {
@@ -47,7 +47,7 @@ impl<'a> ToHex for &'a [u8] {
47
47
}
48
48
49
49
unsafe {
50
- str :: raw:: from_utf8_owned ( v)
50
+ string :: raw:: from_utf8 ( v)
51
51
}
52
52
}
53
53
}
You can’t perform that action at this time.
0 commit comments