pub struct NonEmpty<T> { /* private fields */ }Expand description
A collection that cannot be empty.
04-subsystem-contracts.md types the routing token as
Option<NonEmpty<Label>>, and the v1 spike shows why the inner
non-emptiness is load-bearing rather than tidy: generate-jitconfig with
labels: [] returns 422 Invalid property /labels: 1 item required
(docs/spikes/d18-org-jit-verification.md, Point 3). An empty label set is
not a degenerate case to handle at the gateway; it is a value the domain
should not be able to hand out.
crate::policy::RoutingLabels gives a stronger guarantee than this type
and is what a policy actually stores; this type is the shape the contract
document names, and crate::policy::RoutingLabels::to_non_empty produces
it.
Implementations§
Source§impl<T> NonEmpty<T>
impl<T> NonEmpty<T>
pub fn of(first: T) -> Self
Sourcepub fn try_from_vec(
items: Vec<T>,
what: &'static str,
) -> Result<Self, ValidationError>
pub fn try_from_vec( items: Vec<T>, what: &'static str, ) -> Result<Self, ValidationError>
§Errors
ValidationError::NonEmptyRequired when items is empty.
pub fn first(&self) -> &T
Sourcepub fn count(&self) -> NonZeroUsize
pub fn count(&self) -> NonZeroUsize
The number of elements. Never zero, which is why this returns
NonZeroUsize rather than usize and is not called len.