diff options
| author | bors <bors@rust-lang.org> | 2017-11-26 06:49:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-26 06:49:43 +0000 |
| commit | d4dc289f4bd5bff48b4eba393521b3eb899723a8 (patch) | |
| tree | 4a1bf54316539c23dcc2ad8c9fd1d4ba9e9aa549 /src/libstd/sys_common | |
| parent | 2f84fb5cc1ac5f04bdf5a281997e02bcf4fc18d9 (diff) | |
| parent | 1bbc7764461631100c88f5523238a19bc4767199 (diff) | |
| download | rust-d4dc289f4bd5bff48b4eba393521b3eb899723a8.tar.gz rust-d4dc289f4bd5bff48b4eba393521b3eb899723a8.zip | |
Auto merge of #45990 - murarth:rc-from-strs, r=alexcrichton
Implement `Rc`/`Arc` conversions for string-like types
Provides the following conversion implementations:
* `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>`
* `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>`
* `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
Closes #45008
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/wtf8.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/sys_common/wtf8.rs b/src/libstd/sys_common/wtf8.rs index b89a73cd28a..e212b5006f2 100644 --- a/src/libstd/sys_common/wtf8.rs +++ b/src/libstd/sys_common/wtf8.rs @@ -35,8 +35,10 @@ use hash::{Hash, Hasher}; use iter::FromIterator; use mem; use ops; +use rc::Rc; use slice; use str; +use sync::Arc; use sys_common::AsInner; const UTF8_REPLACEMENT_CHARACTER: &'static str = "\u{FFFD}"; @@ -641,6 +643,18 @@ impl Wtf8 { let boxed: Box<[u8]> = Default::default(); unsafe { mem::transmute(boxed) } } + + #[inline] + pub fn into_arc(&self) -> Arc<Wtf8> { + let arc: Arc<[u8]> = Arc::from(&self.bytes); + unsafe { Arc::from_raw(Arc::into_raw(arc) as *const Wtf8) } + } + + #[inline] + pub fn into_rc(&self) -> Rc<Wtf8> { + let rc: Rc<[u8]> = Rc::from(&self.bytes); + unsafe { Rc::from_raw(Rc::into_raw(rc) as *const Wtf8) } + } } |
