pub trait DecodeValue<'a>: Sized {
type Error: Error + From<Error> + 'static;
// Required method
fn decode_value<R: Reader<'a>>(
reader: &mut R,
header: Header,
) -> Result<Self, Self::Error>;
}Expand description
DecodeValue trait parses the value part of a Tag-Length-Value object,
sans the Tag and Length.
As opposed to Decode, implementer is expected to read the inner content only,
without the Header, which was decoded beforehand.
§Example
use der::{Decode, DecodeValue, ErrorKind, FixedTag, Header, Reader, Tag};
/// 1-byte month
struct MyByteMonth(u8);
impl<'a> DecodeValue<'a> for MyByteMonth {
type Error = der::Error;
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> der::Result<Self> {
let month = reader.read_byte()?;
if (0..12).contains(&month) {
Ok(Self(month))
} else {
Err(reader.error(ErrorKind::DateTime))
}
}
}
impl FixedTag for MyByteMonth {
const TAG: Tag = Tag::OctetString;
}
let month = MyByteMonth::from_der(b"\x04\x01\x09").expect("month to decode");
assert_eq!(month.0, 9);Required Associated Types§
Required Methods§
Sourcefn decode_value<R: Reader<'a>>(
reader: &mut R,
header: Header,
) -> Result<Self, Self::Error>
fn decode_value<R: Reader<'a>>( reader: &mut R, header: Header, ) -> Result<Self, Self::Error>
Attempt to decode this value using the provided Reader.
§Errors
Returns Self::Error in the event a decoding error occurred.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a> DecodeValue<'a> for bool
impl<'a> DecodeValue<'a> for bool
Source§impl<'a> DecodeValue<'a> for i8
impl<'a> DecodeValue<'a> for i8
Source§impl<'a> DecodeValue<'a> for i16
impl<'a> DecodeValue<'a> for i16
Source§impl<'a> DecodeValue<'a> for i32
impl<'a> DecodeValue<'a> for i32
Source§impl<'a> DecodeValue<'a> for i64
impl<'a> DecodeValue<'a> for i64
Source§impl<'a> DecodeValue<'a> for i128
impl<'a> DecodeValue<'a> for i128
Source§impl<'a> DecodeValue<'a> for u8
impl<'a> DecodeValue<'a> for u8
Source§impl<'a> DecodeValue<'a> for u16
impl<'a> DecodeValue<'a> for u16
Source§impl<'a> DecodeValue<'a> for u32
impl<'a> DecodeValue<'a> for u32
Source§impl<'a> DecodeValue<'a> for u64
impl<'a> DecodeValue<'a> for u64
Source§impl<'a> DecodeValue<'a> for u128
impl<'a> DecodeValue<'a> for u128
Source§impl<'a> DecodeValue<'a> for ()
impl<'a> DecodeValue<'a> for ()
Source§impl<'a> DecodeValue<'a> for String
Available on crate feature alloc only.
impl<'a> DecodeValue<'a> for String
Available on crate feature
alloc only.Source§impl<'a> DecodeValue<'a> for SystemTime
Available on crate feature std only.
impl<'a> DecodeValue<'a> for SystemTime
Available on crate feature
std only.Source§impl<'a, T> DecodeValue<'a> for Box<T>where
T: DecodeValue<'a>,
Available on crate feature alloc only.
impl<'a, T> DecodeValue<'a> for Box<T>where
T: DecodeValue<'a>,
Available on crate feature
alloc only.Source§impl<'a, T> DecodeValue<'a> for Vec<T>where
T: Decode<'a>,
Available on crate feature alloc only.
impl<'a, T> DecodeValue<'a> for Vec<T>where
T: Decode<'a>,
Available on crate feature
alloc only.Source§impl<'a, T, E> DecodeValue<'a> for Cow<'a, T>where
T: ToOwned + ?Sized,
&'a T: DecodeValue<'a, Error = E>,
T::Owned: for<'b> DecodeValue<'b, Error = E>,
E: Error + From<Error> + 'static,
Available on crate feature alloc only.
impl<'a, T, E> DecodeValue<'a> for Cow<'a, T>where
T: ToOwned + ?Sized,
&'a T: DecodeValue<'a, Error = E>,
T::Owned: for<'b> DecodeValue<'b, Error = E>,
E: Error + From<Error> + 'static,
Available on crate feature
alloc only.