pub struct ParseErrors(/* private fields */);
Expand description
Represents one or more ParseError
s encountered when parsing a policy or
template.
Methods from Deref<Target = NonEmpty<ParseError>>§
Sourcepub fn first_mut(&mut self) -> &mut T
pub fn first_mut(&mut self) -> &mut T
Get the mutable reference to the first element. Never fails.
§Examples
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::new(42);
let head = non_empty.first_mut();
*head += 1;
assert_eq!(non_empty.first(), &43);
let mut non_empty = NonEmpty::from((1, vec![4, 2, 3]));
let head = non_empty.first_mut();
*head *= 42;
assert_eq!(non_empty.first(), &42);
Sourcepub fn tail(&self) -> &[T]
pub fn tail(&self) -> &[T]
Get the possibly-empty tail of the list.
use nonempty::NonEmpty;
let non_empty = NonEmpty::new(42);
assert_eq!(non_empty.tail(), &[]);
let non_empty = NonEmpty::from((1, vec![4, 2, 3]));
assert_eq!(non_empty.tail(), &[4, 2, 3]);
Sourcepub fn insert(&mut self, index: usize, element: T)
pub fn insert(&mut self, index: usize, element: T)
Inserts an element at position index within the vector, shifting all elements after it to the right.
§Panics
Panics if index > len.
§Examples
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::from((1, vec![2, 3]));
non_empty.insert(1, 4);
assert_eq!(non_empty, NonEmpty::from((1, vec![4, 2, 3])));
non_empty.insert(4, 5);
assert_eq!(non_empty, NonEmpty::from((1, vec![4, 2, 3, 5])));
non_empty.insert(0, 42);
assert_eq!(non_empty, NonEmpty::from((42, vec![1, 4, 2, 3, 5])));
Sourcepub fn len_nonzero(&self) -> NonZero<usize>
pub fn len_nonzero(&self) -> NonZero<usize>
Gets the length of the list as a NonZeroUsize.
Sourcepub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
pub fn contains(&self, x: &T) -> boolwhere
T: PartialEq,
Check whether an element is contained in the list.
use nonempty::NonEmpty;
let mut l = NonEmpty::from((42, vec![36, 58]));
assert!(l.contains(&42));
assert!(!l.contains(&101));
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncate the list to a certain size. Must be greater than 0
.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
use nonempty::NonEmpty;
let mut l = NonEmpty::from((42, vec![36, 58]));
let mut l_iter = l.iter();
assert_eq!(l_iter.len(), 3);
assert_eq!(l_iter.next(), Some(&42));
assert_eq!(l_iter.next(), Some(&36));
assert_eq!(l_iter.next(), Some(&58));
assert_eq!(l_iter.next(), None);
Sourcepub fn iter_mut(&mut self) -> impl DoubleEndedIterator
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator
use nonempty::NonEmpty;
let mut l = NonEmpty::new(42);
l.push(36);
l.push(58);
for i in l.iter_mut() {
*i *= 10;
}
let mut l_iter = l.iter();
assert_eq!(l_iter.next(), Some(&420));
assert_eq!(l_iter.next(), Some(&360));
assert_eq!(l_iter.next(), Some(&580));
assert_eq!(l_iter.next(), None);
Sourcepub fn split_first(&self) -> (&T, &[T])
pub fn split_first(&self) -> (&T, &[T])
Deconstruct a NonEmpty
into its head and tail.
This operation never fails since we are guranteed
to have a head element.
§Example Use
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::from((1, vec![2, 3, 4, 5]));
// Guaranteed to have the head and we also get the tail.
assert_eq!(non_empty.split_first(), (&1, &[2, 3, 4, 5][..]));
let non_empty = NonEmpty::new(1);
// Guaranteed to have the head element.
assert_eq!(non_empty.split_first(), (&1, &[][..]));
Sourcepub fn split(&self) -> (&T, &[T], &T)
pub fn split(&self) -> (&T, &[T], &T)
Deconstruct a NonEmpty
into its first, last, and
middle elements, in that order.
If there is only one element then first == last.
§Example Use
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::from((1, vec![2, 3, 4, 5]));
// Guaranteed to have the last element and the elements
// preceding it.
assert_eq!(non_empty.split(), (&1, &[2, 3, 4][..], &5));
let non_empty = NonEmpty::new(1);
// Guaranteed to have the last element.
assert_eq!(non_empty.split(), (&1, &[][..], &1));
Sourcepub fn append(&mut self, other: &mut Vec<T>)
pub fn append(&mut self, other: &mut Vec<T>)
Append a Vec
to the tail of the NonEmpty
.
§Example Use
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::new(1);
let mut vec = vec![2, 3, 4, 5];
non_empty.append(&mut vec);
let mut expected = NonEmpty::from((1, vec![2, 3, 4, 5]));
assert_eq!(non_empty, expected);
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
Binary searches this sorted non-empty vector for a given element.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned.
If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]));
assert_eq!(non_empty.binary_search(&0), Ok(0));
assert_eq!(non_empty.binary_search(&13), Ok(9));
assert_eq!(non_empty.binary_search(&4), Err(7));
assert_eq!(non_empty.binary_search(&100), Err(13));
let r = non_empty.binary_search(&1);
assert!(match r { Ok(1..=4) => true, _ => false, });
If you want to insert an item to a sorted non-empty vector, while maintaining sort order:
use nonempty::NonEmpty;
let mut non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]));
let num = 42;
let idx = non_empty.binary_search(&num).unwrap_or_else(|x| x);
non_empty.insert(idx, num);
assert_eq!(non_empty, NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55])));
Sourcepub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Binary searches this sorted non-empty with a comparator function.
The comparator function should implement an order consistent with the sort order of the underlying slice, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
§Examples
Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1,4].
use nonempty::NonEmpty;
let non_empty = NonEmpty::from((0, vec![1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]));
let seek = 0;
assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Ok(0));
let seek = 13;
assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Ok(9));
let seek = 4;
assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Err(7));
let seek = 100;
assert_eq!(non_empty.binary_search_by(|probe| probe.cmp(&seek)), Err(13));
let seek = 1;
let r = non_empty.binary_search_by(|probe| probe.cmp(&seek));
assert!(match r { Ok(1..=4) => true, _ => false, });
Sourcepub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Binary searches this sorted non-empty vector with a key extraction function.
Assumes that the vector is sorted by the key.
If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.
§Examples
Looks up a series of four elements in a non-empty vector of pairs sorted by their second elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1, 4].
use nonempty::NonEmpty;
let non_empty = NonEmpty::from((
(0, 0),
vec![(2, 1), (4, 1), (5, 1), (3, 1),
(1, 2), (2, 3), (4, 5), (5, 8), (3, 13),
(1, 21), (2, 34), (4, 55)]
));
assert_eq!(non_empty.binary_search_by_key(&0, |&(a,b)| b), Ok(0));
assert_eq!(non_empty.binary_search_by_key(&13, |&(a,b)| b), Ok(9));
assert_eq!(non_empty.binary_search_by_key(&4, |&(a,b)| b), Err(7));
assert_eq!(non_empty.binary_search_by_key(&100, |&(a,b)| b), Err(13));
let r = non_empty.binary_search_by_key(&1, |&(a,b)| b);
assert!(match r { Ok(1..=4) => true, _ => false, });
Sourcepub fn maximum(&self) -> &Twhere
T: Ord,
pub fn maximum(&self) -> &Twhere
T: Ord,
Returns the maximum element in the non-empty vector.
This will return the first item in the vector if the tail is empty.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::new(42);
assert_eq!(non_empty.maximum(), &42);
let non_empty = NonEmpty::from((1, vec![-34, 42, 76, 4, 5]));
assert_eq!(non_empty.maximum(), &76);
Sourcepub fn minimum(&self) -> &Twhere
T: Ord,
pub fn minimum(&self) -> &Twhere
T: Ord,
Returns the minimum element in the non-empty vector.
This will return the first item in the vector if the tail is empty.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::new(42);
assert_eq!(non_empty.minimum(), &42);
let non_empty = NonEmpty::from((1, vec![-34, 42, 76, 4, 5]));
assert_eq!(non_empty.minimum(), &-34);
Sourcepub fn maximum_by<'a, F>(&'a self, compare: F) -> &'a T
pub fn maximum_by<'a, F>(&'a self, compare: F) -> &'a T
Returns the element that gives the maximum value with respect to the specified comparison function.
This will return the first item in the vector if the tail is empty.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::new((0, 42));
assert_eq!(non_empty.maximum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 42));
let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
assert_eq!(non_empty.maximum_by(|(k, _), (l, _)| k.cmp(l)), &(4, 42));
Sourcepub fn minimum_by<'a, F>(&'a self, compare: F) -> &'a T
pub fn minimum_by<'a, F>(&'a self, compare: F) -> &'a T
Returns the element that gives the minimum value with respect to the specified comparison function.
This will return the first item in the vector if the tail is empty.
use nonempty::NonEmpty;
let non_empty = NonEmpty::new((0, 42));
assert_eq!(non_empty.minimum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 42));
let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
assert_eq!(non_empty.minimum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 76));
Sourcepub fn maximum_by_key<'a, U, F>(&'a self, f: F) -> &'a T
pub fn maximum_by_key<'a, U, F>(&'a self, f: F) -> &'a T
Returns the element that gives the maximum value with respect to the specified function.
This will return the first item in the vector if the tail is empty.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::new((0, 42));
assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(0, 42));
let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(4, 42));
assert_eq!(non_empty.maximum_by_key(|(k, _)| -k), &(0, 76));
Sourcepub fn minimum_by_key<'a, U, F>(&'a self, f: F) -> &'a T
pub fn minimum_by_key<'a, U, F>(&'a self, f: F) -> &'a T
Returns the element that gives the minimum value with respect to the specified function.
This will return the first item in the vector if the tail is empty.
§Examples
use nonempty::NonEmpty;
let non_empty = NonEmpty::new((0, 42));
assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 42));
let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 76));
assert_eq!(non_empty.minimum_by_key(|(k, _)| -k), &(4, 42));
Trait Implementations§
Source§impl AsMut<NonEmpty<ParseError>> for ParseErrors
impl AsMut<NonEmpty<ParseError>> for ParseErrors
Source§fn as_mut(&mut self) -> &mut NonEmpty<ParseError>
fn as_mut(&mut self) -> &mut NonEmpty<ParseError>
Source§impl AsRef<NonEmpty<ParseError>> for ParseErrors
impl AsRef<NonEmpty<ParseError>> for ParseErrors
Source§fn as_ref(&self) -> &NonEmpty<ParseError>
fn as_ref(&self) -> &NonEmpty<ParseError>
Source§impl Clone for ParseErrors
impl Clone for ParseErrors
Source§fn clone(&self) -> ParseErrors
fn clone(&self) -> ParseErrors
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ParseErrors
impl Debug for ParseErrors
Source§impl DerefMut for ParseErrors
impl DerefMut for ParseErrors
Source§impl Diagnostic for ParseErrors
impl Diagnostic for ParseErrors
Diagnostic
s.Source§fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
. Ideally also globally unique, and documented
in the toplevel crate’s documentation for easy searching. Rust path
format (foo::bar::baz
) is recommended, but more classic codes like
E0123
or enums will work just fine.Source§fn severity(&self) -> Option<Severity>
fn severity(&self) -> Option<Severity>
ReportHandler
s to change the display format
of this diagnostic. Read moreSource§fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
. Do you have any
advice for the poor soul who’s just run into this issue?Source§fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic
.Source§fn source_code(&self) -> Option<&dyn SourceCode>
fn source_code(&self) -> Option<&dyn SourceCode>
Diagnostic
’s Diagnostic::labels
to.Source§fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
Diagnostic
’s Diagnostic::source_code
Source§fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
Source§impl Display for ParseErrors
impl Display for ParseErrors
Source§impl Error for ParseErrors
impl Error for ParseErrors
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl<T: Into<ParseError>> Extend<T> for ParseErrors
impl<T: Into<ParseError>> Extend<T> for ParseErrors
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl From<ParseErrors> for LiteralParseError
impl From<ParseErrors> for LiteralParseError
Source§fn from(source: ParseErrors) -> Self
fn from(source: ParseErrors) -> Self
Source§impl From<ParseErrors> for RestrictedExpressionParseError
impl From<ParseErrors> for RestrictedExpressionParseError
Source§fn from(source: ParseErrors) -> Self
fn from(source: ParseErrors) -> Self
Source§impl<T: Into<ParseError>> From<T> for ParseErrors
impl<T: Into<ParseError>> From<T> for ParseErrors
Source§impl<'a> IntoIterator for &'a ParseErrors
impl<'a> IntoIterator for &'a ParseErrors
Source§type Item = &'a ParseError
type Item = &'a ParseError
Source§type IntoIter = Chain<Once<<&'a ParseErrors as IntoIterator>::Item>, Iter<'a, ParseError>>
type IntoIter = Chain<Once<<&'a ParseErrors as IntoIterator>::Item>, Iter<'a, ParseError>>
Source§impl IntoIterator for ParseErrors
impl IntoIterator for ParseErrors
Source§type Item = ParseError
type Item = ParseError
Source§type IntoIter = Chain<Once<<ParseErrors as IntoIterator>::Item>, IntoIter<<ParseErrors as IntoIterator>::Item>>
type IntoIter = Chain<Once<<ParseErrors as IntoIterator>::Item>, IntoIter<<ParseErrors as IntoIterator>::Item>>
Source§impl PartialEq for ParseErrors
impl PartialEq for ParseErrors
Source§impl Deref for ParseErrors
impl Deref for ParseErrors
impl Eq for ParseErrors
impl StructuralPartialEq for ParseErrors
Auto Trait Implementations§
impl Freeze for ParseErrors
impl RefUnwindSafe for ParseErrors
impl Send for ParseErrors
impl Sync for ParseErrors
impl Unpin for ParseErrors
impl UnwindSafe for ParseErrors
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more