Skip to main content

ManaCost

Struct ManaCost 

Source
pub struct ManaCost { /* private fields */ }
Expand description

A complete mana cost (e.g. {2}{W}{U}). Mirrors Java ManaCost. Immutable once constructed.

Implementations§

Source§

impl ManaCost

Source

pub fn no_cost() -> Self

Represents a card with no mana cost (e.g. lands).

Source

pub fn zero() -> Self

Zero mana cost {0}.

Source

pub fn generic(n: i32) -> Self

Pure generic cost (e.g. {3}).

Source

pub fn parse(s: &str) -> Self

Parse a mana cost string in Forge format (space-separated tokens). E.g. “2 W U”, “3 G G”, “X R”, “0”, “W/U W/U”.

Source

pub fn cmc(&self) -> i32

Source

pub fn color_profile(&self) -> u8

Source

pub fn color_set(&self) -> ColorSet

Source

pub fn generic_cost(&self) -> i32

Source

pub fn shards(&self) -> &[ManaCostShard]

Source

pub fn is_no_cost(&self) -> bool

Source

pub fn is_zero(&self) -> bool

Source

pub fn is_pure_generic(&self) -> bool

Source

pub fn count_x(&self) -> usize

Source

pub fn has_phyrexian(&self) -> bool

Source

pub fn from_parts(shards: Vec<ManaCostShard>, generic_cost: i32) -> ManaCost

Build a ManaCost from explicit shards and generic cost.

Source

pub fn without_x(&self) -> ManaCost

Return a copy of this cost with all X shards removed. Used to compute the non-X portion for affordability checks.

Source

pub fn without_phyrexian(&self) -> ManaCost

Return a copy of this cost with all Phyrexian shards removed. Used for playability checks — Phyrexian shards can always be paid with 2 life.

Source

pub fn phyrexian_to_colored(&self) -> ManaCost

Convert phyrexian shards to their colored equivalents (e.g. {B/P} → {B}). Non-phyrexian shards are kept as-is. Generic cost is preserved.

Source

pub fn colored_to_phyrexian(&self, color_mask: u8) -> ManaCost

Convert mono-colored shards of the given color into their phyrexian variants. Used for effects like “you may pay 2 life rather than pay {B}”.

Source

pub fn shard_count(&self, which: ManaCostShard) -> usize

Source

pub fn add(&self, other: &ManaCost) -> ManaCost

Add another mana cost to this one, returning the combined cost.

Source

pub fn reduce_generic(&self, amount: i32) -> ManaCost

Reduce the generic portion of this cost by amount (floor at 0). Used for Emerge (cost reduced by sacrificed creature’s mana value).

Source

pub fn with_generic(&self, generic: i32) -> ManaCost

Return a copy with the generic cost set to the given value.

Source

pub fn has_color_shard(&self, atom: u16) -> bool

Check if this cost has a mono-color shard matching the given ManaAtom.

Source

pub fn remove_color_shard(&self, atom: u16) -> ManaCost

Remove one mono-color shard matching the given ManaAtom. Returns new cost.

Source

pub fn reduce_color( &self, color: Color, count: i32, ignore_generic: bool, ) -> ManaCost

Remove up to count colored shards matching color from this cost. If ignore_generic is true, only removes colored shards (never converts to generic reduction). If ignore_generic is false and fewer matching shards exist than count, the remainder reduces the generic portion instead.

Source

pub fn combine(a: &ManaCost, b: &ManaCost) -> ManaCost

Trait Implementations§

Source§

impl Clone for ManaCost

Source§

fn clone(&self) -> ManaCost

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 ManaCost

Source§

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

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

impl<'de> Deserialize<'de> for ManaCost

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 Display for ManaCost

Source§

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

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

impl Eq for ManaCost

Source§

impl Hash for ManaCost

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 ManaCost

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for ManaCost

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

impl StructuralPartialEq for ManaCost

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V