pub struct Reporter(/* private fields */);Expand description
A collection for tracking fatal errors without halting. Participating
functions return ProjectResult even if they only ever construct Ok. When
they call other participating functions, instead of directly forwarding
errors with ? they should prefer constructing a fallback value with
Reporter::fallback. If any error is added to a Reporter in a function,
the return value is valid but its meaning need not be related in any way to
the inputs.
Returning Err from a function that accepts &mut Reporter indicates not
that there was a fatal error but that it wasn’t possible to construct a
fallback, so if it can, the caller should construct one.
Implementations§
Source§impl Reporter
impl Reporter
Sourcepub fn failing(&self) -> bool
pub fn failing(&self) -> bool
Returns true if any errors were regorded. If this ever returns true, it will always return true in the future.
Sourcepub fn report(&self, error: ProjectErrorObj)
pub fn report(&self, error: ProjectErrorObj)
Report a fatal error
Sourcepub fn fallback<T>(
&self,
res: ProjectResult<T>,
cb: impl FnOnce(ProjectErrorObj) -> T,
) -> T
pub fn fallback<T>( &self, res: ProjectResult<T>, cb: impl FnOnce(ProjectErrorObj) -> T, ) -> T
Catch a fatal error, report it, and substitute the value
Sourcepub fn assert_exit(&self)
pub fn assert_exit(&self)
Exit with code -1 if there were errors
Sourcepub fn unwrap<T>(&self, res: ProjectResult<T>) -> T
pub fn unwrap<T>(&self, res: ProjectResult<T>) -> T
Panic with descriptive messages if there were errors. If there were no errors, unwrap the result
Sourcepub fn unwrap_exit<T>(&self, res: ProjectResult<T>) -> T
pub fn unwrap_exit<T>(&self, res: ProjectResult<T>) -> T
Print errors and exit if any occurred. If there were no errors, unwrap the result
Sourcepub fn into_errors(self) -> Option<Vec<ProjectErrorObj>>
pub fn into_errors(self) -> Option<Vec<ProjectErrorObj>>
Take the errors out of the reporter
Sourcepub fn bind(self) -> ProjectResult<()>
pub fn bind(self) -> ProjectResult<()>
Raise an error if the reporter contains any errors
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Reporter
impl !RefUnwindSafe for Reporter
impl !Sync for Reporter
impl !UnwindSafe for Reporter
impl Send for Reporter
impl Unpin for Reporter
impl UnsafeUnpin for Reporter
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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