pub struct RasnEncodeError {
pub kind: Box<EncodeErrorKind>,
pub codec: Codec,
}Expand description
An error type for failed encoding for every encoder. Abstracts over the different generic and codec-specific errors.
kind field is used to determine the kind of error that occurred.
codec field is used to determine the codec that failed.
backtrace field is used to determine the backtrace of the error.
There is Kind::CodecSpecific variant which wraps the codec-specific
errors as CodecEncodeError type.
§Example
use rasn::{Codec, error::{EncodeErrorKind, strings::PermittedAlphabetError}, prelude::*};
#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq)]
#[rasn(delegate, from("a..z"))]
struct MyConstrainedString (
VisibleString,
);
// Below sample requires that `backtraces` feature is enabled
let constrained_str = MyConstrainedString(VisibleString::try_from("abcD").unwrap());
let encoded = Codec::Uper.encode_to_binary(&constrained_str);
match encoded {
Ok(succ) => {
println!("Successful encoding!");
dbg!(succ);
}
Err(e) => {
// e is EncodeError, Kind is boxed
match *e.kind {
EncodeErrorKind::AlphabetConstraintNotSatisfied {
reason: PermittedAlphabetError::CharacterNotFound {character },
} => {
println!("Codec: {}", e.codec);
println!("Character {} not found from the permitted list.",
char::from_u32(character).unwrap());
#[cfg(feature = "backtraces")]
println!("Backtrace:\n{}", e.backtrace);
}
_ => {
panic!("Unexpected error!");
}
}
}
}
// Should print ->
//
// Codec: UPER
// Character D not found from the permitted list.
// Backtrace: ...Fields§
§kind: Box<EncodeErrorKind>The inner encoding error.
codec: CodecThe codec associated with the error.
Implementations§
Source§impl EncodeError
impl EncodeError
Sourcepub fn alphabet_constraint_not_satisfied(
reason: PermittedAlphabetError,
codec: Codec,
) -> EncodeError
pub fn alphabet_constraint_not_satisfied( reason: PermittedAlphabetError, codec: Codec, ) -> EncodeError
Returns an encode error for codec when the alphabet constraint is not satisfied.
Sourcepub fn size_constraint_not_satisfied(
size: usize,
expected: &Size,
codec: Codec,
) -> EncodeError
pub fn size_constraint_not_satisfied( size: usize, expected: &Size, codec: Codec, ) -> EncodeError
Returns an encode error for codec when the size constraint is not satisfied.
The size is the actual size that failed the constraint and expected the expected size.
Sourcepub fn value_constraint_not_satisfied(
value: BigInt,
expected: &Bounded<i128>,
codec: Codec,
) -> EncodeError
pub fn value_constraint_not_satisfied( value: BigInt, expected: &Bounded<i128>, codec: Codec, ) -> EncodeError
Returns an encode error for codec when the value constraint is not satisfied.
The value is the actual value that failed the constraint.
Sourcepub fn check_length(
length: usize,
expected: &Size,
codec: Codec,
) -> Result<(), EncodeError>
pub fn check_length( length: usize, expected: &Size, codec: Codec, ) -> Result<(), EncodeError>
Check the passed length against the expected size and return an error if it does not match.
Sourcepub fn length_exceeds_platform_size(codec: Codec) -> EncodeError
pub fn length_exceeds_platform_size(codec: Codec) -> EncodeError
Create an encode error for codec when the value is too large to be encoded on the current platform.
Sourcepub fn integer_type_conversion_failed(msg: String, codec: Codec) -> EncodeError
pub fn integer_type_conversion_failed(msg: String, codec: Codec) -> EncodeError
Create an error for failed conversion from BitInt or BigUint to primitive integer types
Sourcepub fn opaque_conversion_failed(msg: String, codec: Codec) -> EncodeError
pub fn opaque_conversion_failed(msg: String, codec: Codec) -> EncodeError
Create an error if conversion to opaque type failed.
This is mainly used as part of SMI standard which converts type to BER encoding and handles bytes as Opaque.
Sourcepub fn variant_not_in_choice(codec: Codec) -> EncodeError
pub fn variant_not_in_choice(codec: Codec) -> EncodeError
Create an error when the selected variant is not found in the choice.
Sourcepub fn real_not_supported(codec: Codec) -> EncodeError
pub fn real_not_supported(codec: Codec) -> EncodeError
Returns an encode error when the encoder doesn’t support REAL type.
Sourcepub fn from_kind(kind: EncodeErrorKind, codec: Codec) -> EncodeError
pub fn from_kind(kind: EncodeErrorKind, codec: Codec) -> EncodeError
A helper function to construct an EncodeError from the given kind and codec.
Trait Implementations§
Source§impl Debug for EncodeError
impl Debug for EncodeError
Source§impl Display for EncodeError
impl Display for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
Source§impl Error for EncodeError
impl Error for EncodeError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<AperEncodeErrorKind> for EncodeError
impl From<AperEncodeErrorKind> for EncodeError
Source§fn from(error: AperEncodeErrorKind) -> EncodeError
fn from(error: AperEncodeErrorKind) -> EncodeError
Source§impl From<BerEncodeErrorKind> for EncodeError
impl From<BerEncodeErrorKind> for EncodeError
Source§fn from(error: BerEncodeErrorKind) -> EncodeError
fn from(error: BerEncodeErrorKind) -> EncodeError
Source§impl From<CerEncodeErrorKind> for EncodeError
impl From<CerEncodeErrorKind> for EncodeError
Source§fn from(error: CerEncodeErrorKind) -> EncodeError
fn from(error: CerEncodeErrorKind) -> EncodeError
Source§impl From<CodecEncodeError> for EncodeError
impl From<CodecEncodeError> for EncodeError
Source§fn from(error: CodecEncodeError) -> EncodeError
fn from(error: CodecEncodeError) -> EncodeError
Source§impl From<CoerEncodeErrorKind> for EncodeError
impl From<CoerEncodeErrorKind> for EncodeError
Source§fn from(error: CoerEncodeErrorKind) -> EncodeError
fn from(error: CoerEncodeErrorKind) -> EncodeError
Source§impl From<DerEncodeErrorKind> for EncodeError
impl From<DerEncodeErrorKind> for EncodeError
Source§fn from(error: DerEncodeErrorKind) -> EncodeError
fn from(error: DerEncodeErrorKind) -> EncodeError
Source§impl From<EncodeError> for Error
impl From<EncodeError> for Error
Source§fn from(source: RasnEncodeError) -> Self
fn from(source: RasnEncodeError) -> Self
Source§impl From<JerEncodeErrorKind> for EncodeError
impl From<JerEncodeErrorKind> for EncodeError
Source§fn from(error: JerEncodeErrorKind) -> EncodeError
fn from(error: JerEncodeErrorKind) -> EncodeError
Source§impl From<UperEncodeErrorKind> for EncodeError
impl From<UperEncodeErrorKind> for EncodeError
Source§fn from(error: UperEncodeErrorKind) -> EncodeError
fn from(error: UperEncodeErrorKind) -> EncodeError
Source§impl From<XerEncodeErrorKind> for EncodeError
impl From<XerEncodeErrorKind> for EncodeError
Source§fn from(error: XerEncodeErrorKind) -> EncodeError
fn from(error: XerEncodeErrorKind) -> EncodeError
Auto Trait Implementations§
impl Freeze for EncodeError
impl RefUnwindSafe for EncodeError
impl Send for EncodeError
impl Sync for EncodeError
impl Unpin for EncodeError
impl UnsafeUnpin for EncodeError
impl UnwindSafe for EncodeError
Blanket Implementations§
Source§impl<T> AsErrorSource for Twhere
T: Error + 'static,
impl<T> AsErrorSource for Twhere
T: Error + 'static,
Source§fn as_error_source(&self) -> &(dyn Error + 'static)
fn as_error_source(&self) -> &(dyn Error + 'static)
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.