pub struct DeckList { /* private fields */ }
Expand description

The game Marvel Snap allows sharing decks through the use of encoded strings. This simple crate supports both encoding and decoding of that data to support building other tools on top of the deck information.

It does not include actual card data to keep this library simple as cards are added to the pool frequently enough that this would get stale.

Example (To Share)

use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_name("Thanos".to_string());
list.set_cards(&["AntMan", "Agent13", "Quinjet", "Angela",
"Okoye", "Armor", "Falcon", "Mystique", "Lockjaw",
"KaZar", "DevilDinosaur", "Thanos"]);
let code = list.into_code().unwrap();

Example (From Code)

use marvelsnapdeck::DeckList;

let clipboard = "...";
let mut list = DeckList::from_code(clipboard);

Implementations§

Create an empty DeckList to prepare

Set the deck name visible to the player in game

Example
use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_name("Thanos".into());

assert_eq!(list.name(), "Thanos");

Gets the deck name visible to the player in game

Example
use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_name("Thanos".into());

assert_eq!(list.name(), "Thanos");

Set the list of cards.

Example
use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_cards(&["AntMan"]);

let output = list.cards();

assert_eq!(output[0], "AntMan");

Get list of cards as a vector of strings

Example
use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_cards(&["AntMan"]);

let output = list.cards();

assert_eq!(output[0], "AntMan");

Convert a string copied from Marvel Snap into a DeckList.

Panics

Panics if the code cannot be resolved into a valid DeckList struct.

Converts DeckList into a string for pasting into Marvel Snap

For a complete deck, make sure to set both the deck name and include 12 valid cards. For simplicity, this library does not validate if the cards exist in the game.

Example
use marvelsnapdeck::DeckList;

let mut list = DeckList::new();
list.set_name("Thanos".to_string());
list.set_cards(&["AntMan", "Agent13", "Quinjet", "Angela",
"Okoye", "Armor", "Falcon", "Mystique", "Lockjaw",
"KaZar", "DevilDinosaur", "Thanos"]);
let code = list.into_code().unwrap();
Panics

Panics if the underlying card list fails to encode as a string

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.