Struct il2_iltags::tags::payload::ILGenericPayloadTag[][src]

pub struct ILGenericPayloadTag<T: ILTagPayload + Default> { /* fields omitted */ }
Expand description

This generic struct implements a tag that contains a generic payload. The payload must handle all details about the data types and its serialization/ deserialization procedures while this struct will handle the ILTag related functionalities.

This struct implements the trait DefaultWithId which allows it to be used in conjuction with the generic crate::tags::ILDefaultWithIdTagCreator.

A new tag with a custom payload can be defined as follows:

use il2_iltags::io::{Reader, Writer};
use il2_iltags::tags::{ErrorKind, ILTagFactory, Result};
use il2_iltags::tags::payload::*;

struct DummyPayload{};

impl ILTagPayload for DummyPayload {
    fn serialized_size(&self) -> usize {
        // Zero as it has no fields
        0
    }

    fn serialize(&self, writer: &mut dyn Writer) -> Result<()> {
        // Nothing to do as it has no fields
        Ok(())
    }

    fn deserialize(&mut self, _factory: &dyn ILTagFactory, value_size: usize, _reader: &mut dyn Reader) -> Result<()> {
         // The size must be zero as it has no fields
        match value_size {
            0 => Ok(()),
            _ => Err(ErrorKind::CorruptedData),
        }
    }
}

type DummyPayloadTag = ILGenericPayloadTag<DummyPayload>;

In this example, the tag uses DummyPayload as its payload, defining a new tag type DummyPayloadTag.

Easier access to the payload with Deref and DerefMut

Although it this struct is not a smart pointer per se, it is a container for the inner payload implementation and has no other purposed. Given that, the most of the operatons will happen around the payload, not around the tag methods.

Given that, we decided to implement std::ops::Deref and std::ops::DerefMut in order to make the access to the methods of the inner payload easier even if this practice is not recommended for non smart pointer containers.

Since 1.1.1.

Implementations

Trait Implementations

Creates a default tag with. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Returns the ID of the tag.

Retuns the size of the serialized value in bytes.

Serializes the payload of this tag. Read more

Deserializes the value. Read more

Returns a reference as Any.

Returns a mutable reference as Any.

Verifies if this tag is implicity.

Verifies if this tag is reserved.

Returns the total size of the tag in bytes.

Serializes this tag. Read more

Serializes the given tag into an array of bytes. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.