[][src]Enum japi::OptionalVec

pub enum OptionalVec<T> {
    NotPresent,
    One(Option<T>),
    Many(Vec<T>),
}

A rather complicated relative of Option<Vec>

There are a couple places in JSON:API where you have keys with values that can either:

  • Not Exist
  • Be null
  • Contain a single object
  • Contain an array of objects

This enum exists for those cases

OptionalVec::NotPresent exists to specify that the key should not (or did not) exist

OptionalVec::One is None when the value is null and Some when there is a single object

OptionalVec::Many will be used when the value is an array, empty or not

Variants

NotPresent
One(Option<T>)
Many(Vec<T>)

Methods

impl<T> OptionalVec<T>[src]

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

Checks for the OptionalVec::NotPresent variant

Mostly provided to allow serialization to be skipped

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

Checks for the OptionalVec::One variant

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

Checks for the OptionalVec::Many variant

pub fn map<U, F>(self, f: F) -> OptionalVec<U> where
    F: Fn(T) -> U, 
[src]

Map each contained value with the given function

pub fn one_or<E>(self, e: E) -> Result<Option<T>, E>[src]

Error with e if Many, else build an Option

pub fn many_or<E>(self, e: E) -> Result<Vec<T>, E>[src]

Return the contents of Many, else error with e

pub fn into_vec(self) -> Vec<T>[src]

Return all contained items as a Vec

Will map OptionalVec::One(Some(v)) into vec![v]

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

Unwraps One(Some(v))

Panics

Panics for all other variants

pub fn unwrap_many(self) -> Vec<T>[src]

Unwraps Many(v)

Panics

Panics for all other variants

Trait Implementations

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

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

impl<T> Default for OptionalVec<T>[src]

Defaults to OptionalVec::NotPresent

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

impl<T: Eq> Eq for OptionalVec<T>[src]

impl<T: PartialEq> PartialEq<OptionalVec<T>> for OptionalVec<T>[src]

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

impl<T> StructuralEq for OptionalVec<T>[src]

impl<T> StructuralPartialEq for OptionalVec<T>[src]

Auto Trait Implementations

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

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

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

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

impl<T> UnwindSafe for OptionalVec<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: 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.