CardDb

Struct CardDb 

Source
pub struct CardDb {
    pub cards: Vec<CardStatic>,
    /* private fields */
}
Expand description

Loaded card database with cached per-id lookups and compiled abilities.

Fields§

§cards: Vec<CardStatic>

Canonical list of static card definitions.

Implementations§

Source§

impl CardDb

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>

Load a WSDB v2 file from disk.

Source

pub fn from_wsdb_bytes(bytes: &[u8]) -> Result<Self>

Parse a WSDB v2 file from bytes.

Source

pub fn from_postcard_payload(payload: &[u8]) -> Result<Self>

Parse the postcard payload (without WSDB header) into a CardDb.

Source

pub fn schema_version() -> u32

Return the current WSDB schema version supported by this build.

Source

pub fn to_bytes_with_header(&self) -> Result<Vec<u8>>

Serialize this database to a WSDB v2 byte buffer (including header).

Source§

impl CardDb

Source

pub fn new(cards: Vec<CardStatic>) -> Result<Self>

Build a new database from raw card definitions.

Validates ids, canonicalizes templates, and builds per-id caches.

Source

pub fn get(&self, id: CardId) -> Option<&CardStatic>

Look up a card by id. Returns None for invalid or zero ids.

Source

pub fn max_card_id(&self) -> CardId

Maximum card id present in the index.

Source

pub fn is_valid_id(&self, id: CardId) -> bool

Whether an id exists in this database.

Source

pub fn power_by_id(&self, id: CardId) -> i32

Cached power value for a card id, or 0 if invalid.

Source

pub fn soul_by_id(&self, id: CardId) -> u8

Cached soul value for a card id, or 0 if invalid.

Source

pub fn level_by_id(&self, id: CardId) -> u8

Cached level value for a card id, or 0 if invalid.

Source

pub fn cost_by_id(&self, id: CardId) -> u8

Cached cost value for a card id, or 0 if invalid.

Source

pub fn color_by_id(&self, id: CardId) -> CardColor

Cached color value for a card id, defaulting to red.

Source

pub fn card_type_by_id(&self, id: CardId) -> CardType

Cached card type for a card id, defaulting to character.

Source

pub fn iter_card_abilities_in_canonical_order( &self, card_id: CardId, ) -> &[AbilitySpec]

Abilities in canonical order for a given card id.

Source

pub fn compiled_effects_for_ability( &self, card_id: CardId, ability_index: usize, ) -> &[EffectSpec]

Compiled effects for a specific ability on a card.

Source

pub fn compiled_effects_flat(&self, card_id: CardId) -> Vec<EffectSpec>

Flattened list of all compiled effects for a card.

Trait Implementations§

Source§

impl Clone for CardDb

Source§

fn clone(&self) -> CardDb

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CardDb

Source§

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

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

impl<'de> Deserialize<'de> for CardDb

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CardDb

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for CardDb

§

impl RefUnwindSafe for CardDb

§

impl Send for CardDb

§

impl Sync for CardDb

§

impl Unpin for CardDb

§

impl UnwindSafe for CardDb

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,