mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-04 15:51:15 -03:00
common.rs: convenience function to convert to OsString
Even though we generally dont' want to use this type (because it's immutable), it can be advantageous when working with the std::fs API. This is because it implements "AsRef<Path>" which neither of CString and Vec<u8> do.
This commit is contained in:
@@ -24,10 +24,11 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::cell::RefCell;
|
||||
use std::env;
|
||||
use std::ffi::CString;
|
||||
use std::ffi::{CString, OsString};
|
||||
use std::mem::{self, ManuallyDrop};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::os::unix::prelude::OsStringExt;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
@@ -1138,6 +1139,16 @@ pub fn wcs2string(input: &wstr) -> Vec<u8> {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn wcs2osstring(input: &wstr) -> OsString {
|
||||
if input.is_empty() {
|
||||
return OsString::new();
|
||||
}
|
||||
|
||||
let mut result = vec![];
|
||||
wcs2string_appending(&mut result, input);
|
||||
OsString::from_vec(result)
|
||||
}
|
||||
|
||||
pub fn wcs2zstring(input: &wstr) -> CString {
|
||||
if input.is_empty() {
|
||||
return CString::default();
|
||||
|
||||
Reference in New Issue
Block a user