trafix_codec/message/field/value/
mod.rs

1//! Implementation of the value module.
2
3use crate::decoder::num::ParseFixInt;
4
5pub mod aliases;
6pub mod begin_string;
7pub mod msg_type;
8
9/// Trait that abstracts conversion from bytes to values of FIX message fields.
10// TODO(nfejzic): this trait might be obsolete if we decide to wrap used types (i.e. newtype
11// pattern) and implement traits from std such as [`TryFrom`] instead.
12pub(crate) trait FromFixBytes {
13    /// Error returned on failed conversion.
14    type Error<'lifetime>;
15
16    /// Parses the input and returns an instance of self.
17    fn from_fix_bytes(bytes: &[u8]) -> Result<Self, Self::Error<'_>>
18    where
19        Self: Sized;
20}
21
22impl<T> FromFixBytes for T
23where
24    T: ParseFixInt,
25{
26    type Error<'unused> = crate::decoder::num::ParseIntError;
27
28    fn from_fix_bytes(bytes: &[u8]) -> Result<Self, Self::Error<'_>>
29    where
30        Self: Sized,
31    {
32        Self::parse_fix_int(bytes)
33    }
34}