# [−][src]Trait std::ops::Try

    pub trait Try {
        type Ok;
        type Error;
        fn into_result(self) -> Result<Self::Ok, Self::Error>;
        fn from_error(v: Self::Error) -> Self;
        fn from_ok(v: Self::Ok) -> Self;
    }

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

A trait for customizing the behavior of the `?` operator.

A type implementing `Try` is one that has a canonical way to view it in terms of a success/failure dichotomy. This trait allows both extracting those success or failure values from an existing instance and creating a new instance from a success or failure value.

## Associated Types

### `type Ok`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

The type of this value when viewed as successful.

### `type Error`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

The type of this value when viewed as failed.

Loading content...

## Required methods

### `fn into_result(self) -> Result<Self::Ok, Self::Error>`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

Applies the "?" operator. A return of `Ok(t)` means that the execution should continue normally, and the result of `?` is the value `t`. A return of `Err(e)` means that execution should branch to the innermost enclosing `catch`, or return from the function.

If an `Err(e)` result is returned, the value `e` will be "wrapped" in the return type of the enclosing scope (which must itself implement `Try`). Specifically, the value `X::from_error(From::from(e))` is returned, where `X` is the return type of the enclosing function.

### `fn from_error(v: Self::Error) -> Self`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

Wrap an error value to construct the composite result. For example, `Result::Err(x)` and `Result::from_error(x)` are equivalent.

### `fn from_ok(v: Self::Ok) -> Self`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

Wrap an OK value to construct the composite result. For example, `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.

Loading content...

## Implementors

### `impl<T> Try for Option<T>`[src]

#### `type Ok = T`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `type Error = NoneError`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn into_result(self) -> Result<T, NoneError>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_ok(v: T) -> Option<T>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_error(NoneError) -> Option<T>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

### `impl<T, E> Try for Result<T, E>`[src]

#### `type Ok = T`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `type Error = E`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn into_result(self) -> Result<T, E>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_ok(v: T) -> Result<T, E>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_error(v: E) -> Result<T, E>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

### `impl<T, E> Try for Poll<Option<Result<T, E>>>`[src]

#### `type Ok = Poll<Option<T>>`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `type Error = E`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn into_result(
self
) -> Result<<Poll<Option<Result<T, E>>> as Try>::Ok, <Poll<Option<Result<T, E>>> as Try>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_error(
e: <Poll<Option<Result<T, E>>> as Try>::Error
) -> Poll<Option<Result<T, E>>>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_ok(
x: <Poll<Option<Result<T, E>>> as Try>::Ok
) -> Poll<Option<Result<T, E>>>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

### `impl<T, E> Try for Poll<Result<T, E>>`[src]

#### `type Ok = Poll<T>`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `type Error = E`

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn into_result(
self
) -> Result<<Poll<Result<T, E>> as Try>::Ok, <Poll<Result<T, E>> as Try>::Error>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_error(e: <Poll<Result<T, E>> as Try>::Error) -> Poll<Result<T, E>>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)

#### `fn from_ok(x: <Poll<Result<T, E>> as Try>::Ok) -> Poll<Result<T, E>>`[src]

🔬 This is a nightly-only experimental API. (`try_trait` #42327)
Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## 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` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)