Skip to main content

MapKey

Enum MapKey 

Source
pub enum MapKey {
Show 19 variants None, Bool(bool), I8(i8), U8(u8), I16(i16), U16(u16), I32(i32), U32(u32), I64(i64), U64(u64), F32(FloatBits), Vector2([FloatBits; 2]), Vector3([FloatBits; 3]), Vector4([FloatBits; 4]), Matrix44([FloatBits; 16]), Color(Color<u8>), String(String), Hash(HashValue), File(WadHash),
}
Expand description

A map key, owned and free of metadata: every kind Kind::is_valid_map_key admits.

Floats are held as their bit patterns. The key is Eq and Hash, and two keys are equal exactly when the file writes the same bytes for them. The variants carry the client’s names for the tags, as Leaf does.

Variants§

§

None

§

Bool(bool)

§

I8(i8)

§

U8(u8)

§

I16(i16)

§

U16(u16)

§

I32(i32)

§

U32(u32)

§

I64(i64)

§

U64(u64)

§

F32(FloatBits)

§

Vector2([FloatBits; 2])

§

Vector3([FloatBits; 3])

§

Vector4([FloatBits; 4])

§

Matrix44([FloatBits; 16])

Kind::Matrix44, row by row as the wire holds it.

§

Color(Color<u8>)

§

String(String)

§

Hash(HashValue)

Kind::Hash. The value includes its stored width.

§

File(WadHash)

Implementations§

Source§

impl MapKey

Source

pub fn from_literal(literal: &KeyLiteral<'_>, kind: Kind) -> Option<Self>

The key a {key} literal selects in a map keyed by kind, or None when the literal does not convert.

The conversion is the one BinObject::resolve applies to a {key} subscript: a number fills an integer or float key, a string is the text of a string key and is hashed for a Hash or WadChunkLink key, and a number is the raw value of a hashed key.

§Examples
use ltk_hash::{BinHash, Hash as _};
use ltk_meta::{
    path::{KeyLiteral, MapKey},
    property::Kind,
};

let weapon = KeyLiteral::from("weapon");
assert_eq!(
    MapKey::from_literal(&weapon, Kind::Hash),
    Some(MapKey::Hash(BinHash::hash_str("weapon").into()))
);
assert_eq!(MapKey::from_literal(&weapon, Kind::U32), None);
Source§

impl MapKey

Source

pub fn kind(&self) -> Kind

The kind of value this key is.

Source

pub fn from_leaf(leaf: Leaf<'_>) -> Option<Self>

A leaf as a key, or None for a Leaf::Link or a Leaf::Flag. No map is keyed by either.

Source

pub fn to_value(&self) -> PropertyValueEnum

This key as a value of its kind.

Trait Implementations§

Source§

impl Clone for MapKey

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MapKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MapKey

The key as the text inside a {key} segment of the hash form: an integer in decimal, a float in its shortest round-trip form, a string as a JSON string, a hash as lowercase zero-padded hex, a vector, colour or matrix as its components in parentheses, and None as nothing.

§Examples

use ltk_hash::BinHash;
use ltk_meta::path::MapKey;

assert_eq!(MapKey::String("weapon".into()).to_string(), r#""weapon""#);
assert_eq!(MapKey::Hash(BinHash(0x1e6b_a0c4).into()).to_string(), "1e6ba0c4");
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MapKey

Source§

impl Hash for MapKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MapKey

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MapKey

Source§

impl TryFrom<&PropertyValueEnum> for MapKey

Every kind Kind::is_valid_map_key admits converts. Metadata is dropped.

§Errors

Error::InvalidKeyType for a kind no map is keyed by.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &PropertyValueEnum) -> Result<Self, Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.