pub enum ProviderList<T> {
Listed(Vec<T>),
Absent,
}Expand description
A provider list field read from a successful response body.
Successful responses distinguish an explicit list from a body that merely
lacks the field: the provider may omit a list field or serialize it as
JSON null while still reporting success, and an explicit empty array is
authoritative evidence that the listed set is empty. Both absent shapes
decode to ProviderList::Absent; every explicit array decodes to
ProviderList::Listed, including the empty array. Only
ProviderList::Listed rows are evidence a consumer may flatten from.
§Examples
use projectx_client::ProviderList;
let listed: ProviderList<u8> = ProviderList::Listed(Vec::new());
assert!(listed.is_explicitly_empty());
assert_eq!(listed.as_listed(), Some(&[][..]));
assert_eq!(listed.into_listed(), Some(Vec::new()));
let absent: ProviderList<u8> = ProviderList::Absent;
assert!(!absent.is_listed());
assert_eq!(absent.as_listed(), None);
assert_eq!(absent.into_listed(), None);Variants§
Listed(Vec<T>)
The response carried the field with an explicit array, possibly empty.
Absent
The response omitted the field or serialized it as JSON null.
Implementations§
Source§impl<T> ProviderList<T>
impl<T> ProviderList<T>
Sourcepub fn as_listed(&self) -> Option<&[T]>
pub fn as_listed(&self) -> Option<&[T]>
Returns the explicit rows by reference when the provider listed them.
Sourcepub fn into_listed(self) -> Option<Vec<T>>
pub fn into_listed(self) -> Option<Vec<T>>
Returns the explicit rows when the provider listed them.
Sourcepub fn unwrap_or_empty(self) -> Vec<T>
pub fn unwrap_or_empty(self) -> Vec<T>
Returns the explicit rows, or an empty vector when the field was absent.
This discards the distinction between an authoritative empty list and an absent field; prefer matching on the list when that distinction matters.
Sourcepub fn is_explicitly_empty(&self) -> bool
pub fn is_explicitly_empty(&self) -> bool
Returns whether the response carried an authoritative empty array.
This is true only for an explicit empty list; an absent field is not evidence of emptiness.