Trait FieldMap

Source
pub trait FieldMap<F> {
    type Group: RepeatingGroup<Entry = Self>;

    // Required methods
    fn get_raw(&self, field: F) -> Option<&[u8]>;
    fn group(
        &self,
        field: F,
    ) -> Result<Self::Group, FieldValueError<<usize as FieldType<'_>>::Error>>;

    // Provided methods
    fn group_opt(
        &self,
        field: F,
    ) -> Result<Option<Self::Group>, <usize as FieldType<'_>>::Error> { ... }
    fn get<'a, V>(&'a self, field: F) -> Result<V, FieldValueError<V::Error>>
       where V: FieldType<'a> { ... }
    fn get_lossy<'a, V>(
        &'a self,
        field: F,
    ) -> Result<V, FieldValueError<V::Error>>
       where V: FieldType<'a> { ... }
    fn get_opt<'a, V>(&'a self, field: F) -> Result<Option<V>, V::Error>
       where V: FieldType<'a> { ... }
    fn get_lossy_opt<'a, V>(&'a self, field: F) -> Result<Option<V>, V::Error>
       where V: FieldType<'a> { ... }
}
Expand description

Provides random (i.e. non-sequential) access to FIX fields and groups within messages.

§Methods

FieldMap provides two kinds of methods:

  1. Group getters: FieldMap::group and FieldMap::group_opt.

  2. Field getters: FieldMap::get_raw, FieldMap::get, etc..

The most basic form of field access is done via FieldMap::get_raw, which performs no deserialization at all: it simply returns the bytes contents associated with a FIX field, if found.

Building upon FieldMap::get_raw and FieldType, the other field access methods all provide some utility deserialization logic. These methods all have the get_ prefix, with the following considerations:

  • get_lossy methods perform “lossy” deserialization via FieldType::deserialize_lossy. Unlike lossless deserialization, these methods may skip some error checking logic and thus prove to be faster. Memory-safety is still guaranteed, but malformed FIX fields won’t be detected 100% of the time.
  • get_opt methods work exactly like their non-_opt counterparties, but they have a different return type: instead of returning [Err(None)] for missing fields, these methods return None for missing fields and [Some(Ok(field))] for existing fields.

§Type parameters

This trait is generic over a type F, which must univocally identify FIX fields (besides FIX repeating groups, which allow repetitions).

Required Associated Types§

Source

type Group: RepeatingGroup<Entry = Self>

The type returned by FieldMap::group and FieldMap::group_opt.

Required Methods§

Source

fn get_raw(&self, field: F) -> Option<&[u8]>

Looks for a field within self and then returns its raw byte contents, if it exists.

Source

fn group( &self, field: F, ) -> Result<Self::Group, FieldValueError<<usize as FieldType<'_>>::Error>>

Looks for a group that starts with field within self.

Provided Methods§

Source

fn group_opt( &self, field: F, ) -> Result<Option<Self::Group>, <usize as FieldType<'_>>::Error>

Like FieldMap::group, but doesn’t return an Err if the group is missing.

Source

fn get<'a, V>(&'a self, field: F) -> Result<V, FieldValueError<V::Error>>
where V: FieldType<'a>,

Looks for a field within self and then decodes its raw byte contents via FieldType::deserialize, if found.

Source

fn get_lossy<'a, V>(&'a self, field: F) -> Result<V, FieldValueError<V::Error>>
where V: FieldType<'a>,

Like FieldMap::get, but with lossy deserialization.

Source

fn get_opt<'a, V>(&'a self, field: F) -> Result<Option<V>, V::Error>
where V: FieldType<'a>,

Like FieldMap::get, but doesn’t return an Err if field is missing.

Source

fn get_lossy_opt<'a, V>(&'a self, field: F) -> Result<Option<V>, V::Error>
where V: FieldType<'a>,

Like FieldMap::get_opt, but with lossy deserialization.

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.

Implementors§

Source§

impl<'a, F, T> FieldMap<&F> for Message<'a, T>
where F: IsFieldDefinition, T: AsRef<[u8]> + Clone,

Source§

impl<'a, T> FieldMap<u32> for Message<'a, T>
where T: AsRef<[u8]> + Clone,