Skip to main content

GffScalar

Trait GffScalar 

Source
pub trait GffScalar: Sized {
    const GFF_TYPE: GffType;

    // Required methods
    fn from_gff_value(value: &GffValue) -> Option<Self>;
    fn to_gff_value(self) -> GffValue;
}
Expand description

How one Rust type maps onto a GFF value.

§Tolerance belongs in the impl

from_gff_value for i16 accepting an Int32 is that type’s business, stated once, rather than a coercion ladder repeated at every read site. The engine tolerates more encodings than it writes, and this crate has to read the files it merely tolerates.

to_gff_value is the other half and is not its inverse: it emits the one encoding the engine’s own writer produces. A type that reads three widths and writes one is behaving correctly.

Required Associated Constants§

Source

const GFF_TYPE: GffType

The wire type this maps to.

Required Methods§

Source

fn from_gff_value(value: &GffValue) -> Option<Self>

Reads a value, accepting every encoding this type can hold.

None where the value is a type this cannot represent, which the caller treats as the field being absent rather than as an error.

Source

fn to_gff_value(self) -> GffValue

Writes the one encoding the engine’s own writer emits.

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 GffScalar for bool

A bool is carried as a UInt8 almost everywhere and as a UInt16 once, which is why the file’s type is a fact to record rather than to derive from the Rust type.

Source§

const GFF_TYPE: GffType = GffType::UInt8

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for f32

Source§

const GFF_TYPE: GffType = GffType::Single

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for f64

Source§

const GFF_TYPE: GffType = GffType::Double

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for i8

Source§

const GFF_TYPE: GffType = GffType::Int8

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for i16

Source§

const GFF_TYPE: GffType = GffType::Int16

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for i32

Source§

const GFF_TYPE: GffType = GffType::Int32

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for i64

Source§

const GFF_TYPE: GffType = GffType::Int64

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for u8

Source§

const GFF_TYPE: GffType = GffType::UInt8

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for u16

Source§

const GFF_TYPE: GffType = GffType::UInt16

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for u32

Source§

const GFF_TYPE: GffType = GffType::UInt32

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for u64

Source§

const GFF_TYPE: GffType = GffType::UInt64

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for ResRef

Source§

const GFF_TYPE: GffType = GffType::ResRef

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for String

Source§

const GFF_TYPE: GffType = GffType::String

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for Vec<u8>

Source§

const GFF_TYPE: GffType = GffType::Binary

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for [f32; 3]

Source§

const GFF_TYPE: GffType = GffType::Vector3

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Source§

impl GffScalar for [f32; 4]

Source§

const GFF_TYPE: GffType = GffType::Vector4

Source§

fn from_gff_value(value: &GffValue) -> Option<Self>

Source§

fn to_gff_value(self) -> GffValue

Implementors§

Source§

impl GffScalar for GffLocalizedString

Source§

const GFF_TYPE: GffType = GffType::LocalizedString