pub struct ChiselError<F, S> {
pub offset: usize,
pub error: ChiselErrorData<F, S>,
}Expand description
The error type for chiseling operations.
This type provides offset information alongside the error data itself to allow for more precise diagnostics.
§Kinds
This crate distinguishes between 3 ‘kinds’ of errors:
EndOfInput: An unexpected end-of-input condition. If chiseling is retried with additional data provided in the input, it may succeed.Source: TheChisel’s source signalled an error condition.Format: The provided data to chisel is invalid in some way.
Fields§
§offset: usizeThe byte offset that the error occurred at.
This is the offset of the beginning of the erroring operation or item.
error: ChiselErrorData<F, S>The error data itself.
Implementations§
Source§impl<F, S> ChiselError<F, S>
impl<F, S> ChiselError<F, S>
Sourcepub fn new(offset: usize, error: ChiselErrorData<F, S>) -> Self
pub fn new(offset: usize, error: ChiselErrorData<F, S>) -> Self
Creates a new Chisel Error with the provided offset and error data.
Sourcepub fn end_of_input(offset: usize) -> Self
pub fn end_of_input(offset: usize) -> Self
Creates a new “unexpected end-of-input” Chisel Error with the provided offset.
Sourcepub fn source(offset: usize, error: S) -> Self
pub fn source(offset: usize, error: S) -> Self
Creates a new Chisel Source Error with the provided offset and ‘underlying’ error.
Sourcepub fn format(offset: usize, error: F) -> Self
pub fn format(offset: usize, error: F) -> Self
Creates a new Chisel Format Error with the provided offset and detail.
Sourcepub fn map<M: FnOnce(F) -> N, N>(self, mapper: M) -> ChiselError<N, S>
pub fn map<M: FnOnce(F) -> N, N>(self, mapper: M) -> ChiselError<N, S>
Maps a ChiselError<F, S> to ChiselError<N, S> by applying a function to the contained format error, if any.
This can be used to provide additional information about the issue with the provided data.
Note that both EndOfInput and Source errors are returned untouched.
Source§impl<S> ChiselError<Infallible, S>
impl<S> ChiselError<Infallible, S>
Sourcepub fn from_source(offset: usize, error: ChiselSourceError<S>) -> Self
pub fn from_source(offset: usize, error: ChiselSourceError<S>) -> Self
Creates a ChiselError from a ChiselSourceError + an offset.
Sourcepub fn forward<F>(self) -> ChiselError<F, S>
pub fn forward<F>(self) -> ChiselError<F, S>
Convert an InfallibleFormatError into an error with arbitrary format type.
(Note that because Infallible is uninhabited, this is always valid.)
This is basically a small hack to allow easy error propagation,
as ChiselError<F, S> cannot implement From<ChiselError<Infallible, S>>.