Struct bitflags::__core::ffi::OsString
[−]
[src]
pub struct OsString { // some fields omitted }1.0.0
A type that can represent owned, mutable platform-native strings, but is cheaply interconvertable with Rust strings.
The need for this type arises from the fact that:
On Unix systems, strings are often arbitrary sequences of non-zero bytes, in many cases interpreted as UTF-8.
On Windows, strings are often arbitrary sequences of non-zero 16-bit values, interpreted as UTF-16 when it is valid to do so.
In Rust, strings are always valid UTF-8, but may contain zeros.
OsString
and OsStr
bridge this gap by simultaneously representing Rust
and platform-native string values, and in particular allowing a Rust string
to be converted into an "OS" string with no cost.
Methods
impl OsString
fn new() -> OsString
Constructs a new empty OsString
.
fn from_bytes<B>(bytes: B) -> Option<OsString> where B: Into<Vec<u8>>
: RFC was closed, hides subtle Windows semantics
Constructs an OsString
from a byte sequence.
Platform behavior
On Unix systems, any byte sequence can be successfully
converted into an OsString
.
On Windows system, only UTF-8 byte sequences will successfully
convert; non UTF-8 data will produce None
.
fn as_os_str(&self) -> &OsStr
Converts to an OsStr
slice.
fn into_string(self) -> Result<String, OsString>
Converts the OsString
into a String
if it contains valid Unicode data.
On failure, ownership of the original OsString
is returned.
fn push<T>(&mut self, s: T) where T: AsRef<OsStr>
Extends the string with the given &OsStr
slice.
fn with_capacity(capacity: usize) -> OsString
osstring_simple_functions
): recently added
Creates a new OsString
with the given capacity. The string will be
able to hold exactly capacity
bytes without reallocating. If
capacity
is 0, the string will not allocate.
See main OsString
documentation information about encoding.
fn clear(&mut self)
osstring_simple_functions
): recently added
Truncates the OsString
to zero length.
fn capacity(&self) -> usize
osstring_simple_functions
): recently added
Returns the number of bytes this OsString
can hold without
reallocating.
See OsString
introduction for information about encoding.
fn reserve(&mut self, additional: usize)
osstring_simple_functions
): recently added
Reserves capacity for at least additional
more bytes to be inserted
in the given OsString
. The collection may reserve more space to avoid
frequent reallocations.
fn reserve_exact(&mut self, additional: usize)
osstring_simple_functions
): recently added
Reserves the minimum capacity for exactly additional
more bytes to be
inserted in the given OsString
. Does nothing if the capacity is
already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.
Methods from Deref<Target=OsStr>
fn to_str(&self) -> Option<&str>
Yields a &str
slice if the OsStr
is valid unicode.
This conversion may entail doing a check for UTF-8 validity.
fn to_string_lossy(&self) -> Cow<str>
Converts an OsStr
to a Cow<str>
.
Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
fn to_os_string(&self) -> OsString
Copies the slice into an owned OsString
.
fn to_bytes(&self) -> Option<&[u8]>
: RFC was closed, hides subtle Windows semantics
Yields this OsStr
as a byte slice.
Platform behavior
On Unix systems, this is a no-op.
On Windows systems, this returns None
unless the OsStr
is
valid unicode, in which case it produces UTF-8-encoded
data. This may entail checking validity.
fn to_cstring(&self) -> Option<CString>
: RFC was closed, hides subtle Windows semantics
Creates a CString
containing this OsStr
data.
Fails if the OsStr
contains interior nulls.
This is a convenience for creating a CString
from
self.to_bytes()
, and inherits the platform behavior of the
to_bytes
method.
fn is_empty(&self) -> bool
osstring_simple_functions
): recently added
Checks whether the OsStr
is empty.
fn len(&self) -> usize
osstring_simple_functions
): recently added
Returns the number of bytes in this OsStr
.
See OsStr
introduction for information about encoding.