Struct Card

Source
pub struct Card(/* private fields */);

Implementations§

Source§

impl Card

Source

pub fn new(index: usize) -> Card

Source

pub fn index(self) -> usize

Maps the card value back to the index from which it was derived.

Examples found in repository?
examples/count.rs (line 213)
209fn build_lookup() {
210    let cards = cards();
211
212    for (&a, &b) in (0..81).collect::<Vec<_>>().pairs() {
213        let c = (cards[a], cards[b]).complete_set().index();
214        unsafe {
215            SETS[a][b] = c;
216            // `complete_set()` is commutative
217            SETS[b][a] = c;
218        }
219    }
220}
More examples
Hide additional examples
examples/simulate.rs (line 211)
207fn build_lookup() {
208    let cards = cards();
209
210    for (&a, &b) in (0..81).collect::<Vec<_>>().pairs() {
211        let c = (cards[a], cards[b]).complete_set().index();
212        unsafe {
213            SETS[a][b] = c;
214            // `complete_set()` is commutative
215            SETS[b][a] = c;
216        }
217    }
218}
examples/genpng.rs (line 83)
35fn generate_card_images(path: &str, card_width: i32, border: i32,
36                        vertical: bool, scheme: ColorScheme) -> io::Result<()>
37{
38    let card_height = (card_width as f64 / CARD_ASPECT_RATIO).ceil() as i32;
39    let card_rect = Rectangle {
40        // offset by (border, border)
41        x: border as f64,
42        y: border as f64,
43        width: card_width as f64,
44        height: card_height as f64,
45    };
46
47    // add space for the border on each edge
48    let mut ctx_width = card_width + border * 2;
49    let mut ctx_height = card_height + border * 2;
50    if vertical {
51        mem::swap(&mut ctx_width, &mut ctx_height);
52    }
53
54    // create the surface and context
55    let surface = ImageSurface::create(Format::ARgb32, ctx_width, ctx_height)
56        .expect("Could not create surface.");
57    let ctx = Context::new(&surface);
58    if vertical {
59        // adjust the transform to account for the vertical orientation
60        ctx.rotate(FRAC_PI_2);
61        ctx.translate(0.0, -ctx_width as f64);
62    }
63
64    for card in cards() {
65        // completely clear the context to avoid accumulating color on
66        // any edge that antialiases over the transparent background
67        // (e.g. rounded card corners)
68        ctx.save();
69        ctx.set_operator(Operator::Clear);
70        ctx.paint();
71        ctx.restore();
72
73        if border > 0 {
74            ctx.rounded_rect(card_rect, card_corner_radius(card_rect));
75            ctx.set_source_gray(0.0);
76            // half the stroke will be covered by the card
77            ctx.set_line_width(border as f64 * 2.);
78            ctx.stroke();
79        }
80
81        ctx.draw_card(card, card_rect, None, scheme);
82
83        let filename = format!("{}/{}.png", path, card.index());
84        let mut image = File::create(&filename)?;
85
86        surface.write_to_png(&mut image)
87            .unwrap_or_else(|_| println!("Error writing {}", filename));
88    }
89
90    Ok(())
91}
Source§

impl Card

Source

pub fn count(self) -> u8

Returns a shape count in the interval [1,3]

Source

pub fn shape(self) -> Shape

Source

pub fn color(self) -> Color

Source

pub fn shading(self) -> Shading

Trait Implementations§

Source§

impl Clone for Card

Source§

fn clone(&self) -> Card

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 Card

Source§

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

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

impl Ord for Card

Source§

fn cmp(&self, other: &Card) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Card

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Card

Source§

fn partial_cmp(&self, other: &Card) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Card

Source§

impl Eq for Card

Source§

impl StructuralPartialEq for Card

Auto Trait Implementations§

§

impl Freeze for Card

§

impl RefUnwindSafe for Card

§

impl Send for Card

§

impl Sync for Card

§

impl Unpin for Card

§

impl UnwindSafe for Card

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

Source§

fn vzip(self) -> V