mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 10:51:15 -03:00
Add trait to convert FFI reference to &wstr
You can now use a reference to CxxWString or an allocated UniquePtr<CxxWString> to get an &wstr temporary to use without having to allocate again (e.g. via `from_ffi()`).
This commit is contained in:
@@ -153,3 +153,20 @@ fn from_ffi(&self) -> Vec<u8> {
|
|||||||
self.as_bytes().to_vec()
|
self.as_bytes().to_vec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert from FFI types to a reference to a wide string (i.e. a [`wstr`]) without allocating.
|
||||||
|
pub trait AsWstr<'a> {
|
||||||
|
fn as_wstr(&'a self) -> &'a wstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AsWstr<'a> for cxx::UniquePtr<cxx::CxxWString> {
|
||||||
|
fn as_wstr(&'a self) -> &'a wstr {
|
||||||
|
wstr::from_char_slice(self.as_chars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AsWstr<'a> for cxx::CxxWString {
|
||||||
|
fn as_wstr(&'a self) -> &'a wstr {
|
||||||
|
wstr::from_char_slice(self.as_chars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user