mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00: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:
parent
bfe68e6a83
commit
b7638b50e4
1 changed files with 12 additions and 1 deletions
|
@ -24,10 +24,11 @@ use num_traits::ToPrimitive;
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue