# Struct std::ffi::OsStr [−] [src]

    pub struct OsStr {
        // some fields omitted
    }

Slices into OS strings (see `OsString`).

## Methods

### `impl OsStr`

#### `fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &OsStr`

Coerces into an `OsStr` slice.

#### `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]>`

Deprecated since 1.6.0

: 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>`

Deprecated since 1.6.0

: 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.

## Trait Implementations

### `impl PartialEq for OsStr`

#### `fn eq(&self, other: &OsStr) -> bool`

#### `fn ne(&self, other: &Rhs) -> bool`

### `impl PartialEq<str> for OsStr`

#### `fn eq(&self, other: &str) -> bool`

#### `fn ne(&self, other: &Rhs) -> bool`

### `impl Eq for OsStr`

### `impl PartialOrd for OsStr`

#### `fn partial_cmp(&self, other: &OsStr) -> Option<Ordering>`

#### `fn lt(&self, other: &OsStr) -> bool`

#### `fn le(&self, other: &OsStr) -> bool`

#### `fn gt(&self, other: &OsStr) -> bool`

#### `fn ge(&self, other: &OsStr) -> bool`

### `impl PartialOrd<str> for OsStr`

#### `fn partial_cmp(&self, other: &str) -> Option<Ordering>`

#### `fn lt(&self, other: &Rhs) -> bool`

#### `fn le(&self, other: &Rhs) -> bool`

#### `fn gt(&self, other: &Rhs) -> bool`

#### `fn ge(&self, other: &Rhs) -> bool`

### `impl Ord for OsStr`

#### `fn cmp(&self, other: &OsStr) -> Ordering`

### `impl Hash for OsStr`

#### `fn hash<H: Hasher>(&self, state: &mut H)`

#### `fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher`

### `impl Debug for OsStr`

#### `fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>`

### `impl ToOwned for OsStr`

#### `type Owned = OsString`

#### `fn to_owned(&self) -> OsString`

### `impl AsRef<OsStr> for OsStr`

#### `fn as_ref(&self) -> &OsStr`

### `impl OsStrExt for OsStr`

#### `fn from_bytes(slice: &[u8]) -> &OsStr`

#### `fn as_bytes(&self) -> &[u8]`

### `impl AsRef<Path> for OsStr`

#### `fn as_ref(&self) -> &Path`

### `impl OsStrExt for OsStr`

#### `fn from_bytes(slice: &[u8]) -> &OsStr`

#### `fn as_bytes(&self) -> &[u8]`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)