[][src]Enum misskey_core::model::ApiResult

#[must_use =
  "this `ApiResult` may be an `Err` variant, which should be handled"]pub enum ApiResult<T> {
    Err {
        error: ApiError,
    },
    Ok(T),
}

Result type that represents immediate response from Misskey.

ApiResult is either successful response (ApiResult::Ok) or an error (ApiResult::Err) with ApiError. We implement this type in a way that distinguishes it from the Result<T, ApiError>, since the ApiResult is a normal response to a successful request, even if it is an ApiResult::Err. (see the return type of crate::Client::request)

You can convert ApiResult<T> to Result<T, ApiError> by using Into::into or ApiResult::into_result.

Variants

Err

Contains the error value, namely ApiError.

Fields of Err

error: ApiError

The error returned from Misskey.

Ok(T)

Contains the success value.

Implementations

impl<T> ApiResult<T>[src]

pub fn into_result(self) -> Result<T, ApiError>[src]

Converts ApiResult to Result for convenient handling.

You can also use Into::into, but this is preferred as it expresses the intent more clearly.

pub fn ok(self) -> Option<T>[src]

Converts ApiResult<T> to Option<T>, consuming self, and discarding the error, if any.

pub fn err(self) -> Option<ApiError>[src]

Converts ApiResult<T> to Option<ApiError>, consuming self, and discarding the success value, if any.

pub fn is_ok(&self) -> bool[src]

Returns true if the API result is ApiResult::Ok.

pub fn is_err(&self) -> bool[src]

Returns true if the API result is ApiResult::Err.

pub fn expect(self, msg: &str) -> T[src]

Returns the contained ApiResult::Ok value, consuming the self value.

Panics

Panics if the value is an ApiResult::Err, with a panic message including the passed message, and the content of the ApiResult::Err.

pub fn unwrap(self) -> T[src]

Returns the contained ApiResult::Ok value, consuming the self value.

Panics

Panics if the value is an ApiResult::Err, with a panic message provided by the ApiResult::Err's value.

pub fn map<U, F>(self, op: F) -> ApiResult<U> where
    F: FnOnce(T) -> U, 
[src]

Maps a ApiResult<T> to ApiResult<U> by applying a function to a contained ApiResult::Ok value, leaving an ApiResult::Err value untouched.

Trait Implementations

impl<T: Clone> Clone for ApiResult<T>[src]

impl<T: Debug> Debug for ApiResult<T>[src]

impl<'de, T> Deserialize<'de> for ApiResult<T> where
    T: Deserialize<'de>, 
[src]

impl<T> Into<Result<T, ApiError>> for ApiResult<T>[src]

fn into(self) -> Result<T, ApiError>[src]

Converts ApiResult to Result for convenient handling.

impl<T> Serialize for ApiResult<T> where
    T: Serialize
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ApiResult<T> where
    T: RefUnwindSafe

impl<T> Send for ApiResult<T> where
    T: Send

impl<T> Sync for ApiResult<T> where
    T: Sync

impl<T> Unpin for ApiResult<T> where
    T: Unpin

impl<T> UnwindSafe for ApiResult<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.