std::ops::Carrier - Rust
Description: API documentation for the Rust `Carrier` trait in crate `std`.
Keywords: rust, rustlang, rust-lang, Carrier

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

    pub trait Carrier {
        type Success;
        type Error;
        fn from_success(Self::Success) -> Self;
        fn from_error(Self::Error) -> Self;
        fn translate<T>(self) -> T where T: Carrier<Success=Self::Success, Error=Self::Error>;
    }

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

A trait for types which have success and error states and are meant to work with the question mark operator. When the `?` operator is used with a value, whether the value is in the success or error state is determined by calling `translate`.

This trait is very experimental, it will probably be iterated on heavily before it is stabilised. Implementors should expect change. Users of `?` should not rely on any implementations of `Carrier` other than `Result`, i.e., you should not expect `?` to continue to work with `Option`, etc.

## Associated Types

### `type Success`

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

The type of the value when computation succeeds.

### `type Error`

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

The type of the value when computation errors out.

## Required Methods

### `fn from_success(Self::Success) -> Self`

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

Create a `Carrier` from a success value.

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

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

Create a `Carrier` from an error value.

### `fn translate<T>(self) -> T where T: Carrier<Success=Self::Success, Error=Self::Error>`

🔬 This is a nightly-only experimental API. (`question_mark_carrier` #31436)

Translate this `Carrier` to another implementation of `Carrier` with the same associated types.

## Implementors

- `impl<U, V> Carrier for Result<U, V>`

# 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
+
  Collapse/expand 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`)