[−][src]Enum japi::OptionalVec
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
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]
F: Fn(T) -> U,
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]
pub fn unwrap_many(self) -> Vec<T>
[src]
Trait Implementations
impl<T: Clone> Clone for OptionalVec<T>
[src]
fn clone(&self) -> OptionalVec<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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]
T: DeserializeOwned,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<T: Eq> Eq for OptionalVec<T>
[src]
impl<T: PartialEq> PartialEq<OptionalVec<T>> for OptionalVec<T>
[src]
fn eq(&self, other: &OptionalVec<T>) -> bool
[src]
fn ne(&self, other: &OptionalVec<T>) -> bool
[src]
impl<T> Serialize for OptionalVec<T> where
T: Serialize,
[src]
T: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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,
T: RefUnwindSafe,
impl<T> Send for OptionalVec<T> where
T: Send,
T: Send,
impl<T> Sync for OptionalVec<T> where
T: Sync,
T: Sync,
impl<T> Unpin for OptionalVec<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for OptionalVec<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,