diff --git a/fish-rust/src/wchar_ffi.rs b/fish-rust/src/wchar_ffi.rs index dab6c31f3..92c7f7137 100644 --- a/fish-rust/src/wchar_ffi.rs +++ b/fish-rust/src/wchar_ffi.rs @@ -153,3 +153,20 @@ fn from_ffi(&self) -> 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 { + 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()) + } +}