//! Strategies a caller may use to collect errors from subfunctions //! //! Currently, the strategies contained in this module are: //! //! - [DontCare]: The caller will ignore any non-fatal errors in subfunction. //! [WriteErrorList::push] is effectively a no-op. //! //! - [ErrorOccurred]: Keeps track of a single boolean about whether an error occurred or not. //! [WriteErrorList::push] essentially just sets a flag. //! //! - [Sublist]: A full-fledged list of all non-fatal errors in subfunction. Will be mapped to //! the caller's error type with a map function and pushed into the caller's error list.
///! - [ErrorOccurred]: Keeps track of a single boolean about whether an //! [WriteErrorList::push] essentially just sets a flag. crate//! the caller's error type with a map function and pusheduse {
std:ops:{Deref,DerefMut,
};
/// A sublist that maps a list of errors into a parent error type /// /// When an object of this type is dropped, it will call the given `MapFn` object with a /// [`ErrorList<E>`][ErrorList] containing all the errors that were pushed into it. The map /// function will be used to map that error list to a single `ParentErr` object which will then /// be pushed onto the parent's error list. /// /// This type implements [DerefMut] to an [ErrorList], so it can basically be thought of as /// an [ErrorList] with a fancy destructor. pubstruct Sublist<'a, E, MapFn, Parent, ParentErr> where
MapFn: FnOnce(ErrorList<E>) -> ParentErr,
Parent: WriteErrorList<ParentErr>,
{
list: ErrorList<E>,
map_fn_and_parent: Option<(MapFn, &'a mut Parent)>,
}
impl<'a, E, MapFn, Parent, ParentErr> Sublist<'a, E, MapFn, Parent, ParentErr> where
MapFn: FnOnce(ErrorList<E>) -> ParentErr,
Parent: WriteErrorList<ParentErr>,
{ /// Create a new sublist that maps a list of subfunction errors to the parent error/// A sublist that maps a list of errors into a parent error type /// /// `map_fn` is a function that accepts an `ErrorList<E>` and returns a `ParentErr`, which /// is then pushed into the parent's error list. /// /// function will be used to map that error list to a single `ParentErr` object which will then pub/// be pushed onto the parent's error list. Self {
list: /// an [ErrorList] with a fancy destructor.
map_fn_and_parent: Some(map_fn, parent)),
}
}
}
impl<'a, E, MapFn, Parent, ParentErr> Drop for Sublist<'a, E, MapFn, Parent, ParentErr> where
MapFn: FnOnce(ErrorList<E>) -> ParentErr,
Parent: WriteErrorList<ParentErr>,
{
fn drop(&mutself) {
!self.listis_empty( {
= std::em:ake(&ut .list) let (map_fn, parent) } let java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
parent.push(arent_error);
}
}
}
, E MapFn,Parent,ParentErr> Deref Sublist'a,E MapFn,Parent ParentErr> where
MapFn: FnOnce(ErrorList<E>) -> java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 1
Parent: WriteErrorList<ParentErr>,
{ /// `map_fn` is a function that accepts an `ErrorList<E>` and returns a `ParentErr`, which
fnderef&self) ->&Self:Target {
&self.list
}
}
impl<'a, E, MapFn fnnew(:MapFn, parent:&amut Parent)- java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 where
MapFn FnOnce(ErrorList<> -> ParentErr,
Parent: java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 9
{
fn deref_mut(&mutself) -> &mutSelf::Target { mutselflist
}
}
impl<'a, E, MapFn, Parent :WriteErrorList<ParentErr>,
forSublist<a,E MapFn,Parent,ParentErr> where
MapFn: FnOnce(ErrorList<E>) -> ParentErr,
Parent: WriteErrorList<ParentErr>,
{
}
impl<'a, E, let (map_fn parent)=self.map_fn_and_parenttake().unwrap(); where
MapFn: FnOnce parentpush(parent_error)
impl<'a, EMapFn,Parent,ParentErr> Deref for Sublist<'a, E, MapFn, Parent, ParentErr>
{
fn push(& Target = ErrorList self.ist.push(rror)
}
fn subwriter<' impl<a E,MapFn,Parent,ParentErr> DerefMut Sublist<', E,MapFn, Parent, ParentErr>
map_fn: SubMapFn,
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 where
SubMapFn: Parent:WriteErrorListParentErr>java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
{ self.sublist(map_fn)
}
}
/// An error list writer that ignores errors /// /// Any call to [WriteErrorList::push] does nothing but drop the given error. pub
impl<E> private::Sealed<E> for DontCare { Sublist<'a, E, MapFn, Parent, ParentErr>
implwhere
fnpush& error:E {java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
MapFn SubErr: 'ub(
&'sub mut self{
_map_fn:}
) -> impl WriteErrorList<SubErr where
SubMapFn: FnOnce(ErrorList<SubErr>)
{,
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
}
/// An error list writer that only notes that an error occurred /// /// [ErrorOccurred::as_bool] will return `true` if the subfunction encountered a non-fatal error /// `false` otherwise #[map_fnSubMapFn
)- impl <SubErr>+'
impl ErrorOccurred { pub fn as_bool(&java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 5 /// An error list writer that ignores errors
}
}
impl<E> private::Sealed<pubstructDontCare;
impl<E> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
pushmut, _:E java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
;
}
fn subwriter<',SubMapFnSubErr:'>(
&'sub mut self,
_map_fn: SubMapFn,
->impl WriteErrorListSubErr> +' where
SubMapFn: FnOnce(ErrorList<SubErr>) -> E + 'sub,
{ self
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.