diff options
| author | Clar Charr <clar@charr.xyz> | 2017-01-31 22:46:16 -0500 |
|---|---|---|
| committer | Clar Charr <clar@charr.xyz> | 2017-02-14 14:18:43 -0500 |
| commit | 963843b1b346278fcf6f7f065cabdaaae775a0a1 (patch) | |
| tree | 5479442c7fb7a6e7d1c484340246dda7004113dd /src/libstd/sys_common | |
| parent | 2425b227742bb9214d60429d1325816e0b93e152 (diff) | |
| download | rust-963843b1b346278fcf6f7f065cabdaaae775a0a1.tar.gz rust-963843b1b346278fcf6f7f065cabdaaae775a0a1.zip | |
Conversions between CStr/OsStr/Path and boxes.
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/wtf8.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index 0a94ff1e958..1d61181a4ee 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -340,6 +340,12 @@ impl Wtf8Buf { } } } + + /// Converts this `Wtf8Buf` into a boxed `Wtf8`. + #[inline] + pub fn into_box(self) -> Box<Wtf8> { + unsafe { mem::transmute(self.bytes.into_boxed_slice()) } + } } /// Create a new WTF-8 string from an iterator of code points. @@ -583,6 +589,19 @@ impl Wtf8 { _ => None } } + + /// Boxes this `Wtf8`. + #[inline] + pub fn into_box(&self) -> Box<Wtf8> { + let boxed: Box<[u8]> = self.bytes.into(); + unsafe { mem::transmute(boxed) } + } + + /// Creates a boxed, empty `Wtf8`. + pub fn empty_box() -> Box<Wtf8> { + let boxed: Box<[u8]> = Default::default(); + unsafe { mem::transmute(boxed) } + } } |
