Struct marvelsnapdeck::DeckList
source · 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§
source§impl DeckList
impl DeckList
sourcepub fn set_name(&mut self, name: String)
pub fn set_name(&mut self, name: String)
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");
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
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");
sourcepub fn set_cards<T: AsRef<str> + Display>(&mut self, cards: &[T])
pub fn set_cards<T: AsRef<str> + Display>(&mut self, cards: &[T])
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");
sourcepub fn cards(&self) -> Vec<String>
pub fn cards(&self) -> Vec<String>
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");
sourcepub fn from_code<T: AsRef<[u8]>>(code: T) -> Result<Self, DeckListError>
pub fn from_code<T: AsRef<[u8]>>(code: T) -> Result<Self, DeckListError>
Convert a string copied from Marvel Snap into a DeckList.
Panics
Panics if the code cannot be resolved into a valid DeckList struct.
sourcepub fn into_code(&self) -> Result<String, DeckListError>
pub fn into_code(&self) -> Result<String, DeckListError>
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