fn from_str(string: &str) -> Result<Foundations, Self::Err> {
        lazy_static! {
            static ref FOUNDATIONS_RE: Regex = Regex::new(format!(r"(?i)^\s*(foundations:)?\s*(((up\s*to\s*)?{}|empty)\s*(,\s*)?){}$", CARD_PATTERN, "{0,4}").as_str()).unwrap();
            static ref CARD_RE: Regex = Regex::new(format!(r"(?i){}", CARD_PATTERN).as_str()).unwrap();
        }

        if !FOUNDATIONS_RE.is_match(string) {
            return Err(format!("Could not parse foundations: \"{}\"", string))
        }

        let top_cards: Vec<Card> = CARD_RE.find_iter(string)
            .map(|re_match| re_match.as_str().parse().unwrap())
            .collect();

        let mut foundations = Foundations::new();
        for card in top_cards {
            if !foundations.foundation(card.suit).is_empty() {
                return Err(format!("Multiple foundations of suit {} specified", card.suit));
            } else {
                foundations.0[card.suit as usize] = card_sequence_up_to(card);
            }
        }

        Ok(foundations)
    }
/// Converts a `&str` to `Foundations`.
///
/// The input should consist of up to four tokens, where each token consists of either a card or
/// "empty", case-insensitive.
/// The cards follow the format described in [`Card`](struct.Card.html)'s `FromStr`
/// implementation and can optionally be preceded by "up to", case-insensitive.
/// All cards should be of different suits.
/// Each of those cards denotes the highest card in one of the foundations.
/// Tokens can optionally be separated by spaces, commas or both.
///
/// # Examples
///
/// ```
/// # use freecell::Suit::{Club, Diamond, Heart};
/// # use freecell::{Foundations, Card, ACE};
/// assert_eq!("".parse(), Ok(Foundations::new()));
///
/// assert_eq!(
///     "4D 2H AC".parse(),
///     Ok(Foundations([
///         vec![Card { suit: Club, rank: ACE }],
///         Vec::new(),
///         vec![
///             Card { suit: Heart, rank: ACE },
///             Card { suit: Heart, rank: 2 },
///         ],
///         vec![
///             Card { suit: Diamond, rank: ACE },
///             Card { suit: Diamond, rank: 2 },
///             Card { suit: Diamond, rank: 3 },
///             Card { suit: Diamond, rank: 4 },
///         ],
///     ]))
/// );
///
/// assert_eq!(
///     "6C 7S 9C".parse::<Foundations>(),
///     Err("Multiple foundations of suit Club specified".to_string())
/// );
/// ```
Converts a `&str` to `Foundations`.
The input should consist of up to four tokens, where each token consists of either a card or
"empty", case-insensitive.
The cards follow the format described in [`Card`](struct.Card.html)'s `FromStr`
implementation and can optionally be preceded by "up to", case-insensitive.
All cards should be of different suits.
Each of those cards denotes the highest card in one of the foundations.
Tokens can optionally be separated by spaces, commas or both.
Converts a ` &str ` to ` Foundations ` . The input should consist of up to four tokens where each token consists of either a card or " empty " case - insensitive . The cards follow the format described in [ ` Card ` ] ( struct . Card . html ) ' s ` FromStr ` implementation and can optionally be preceded by " up to " case - insensitive . All cards should be of different suits . Each of those cards denotes the highest card in one of the foundations . Tokens can optionally be separated by spaces commas or both .
fn from_str(string: &str) -> Result<Foundations, Self::Err> {
        lazy_static! {
            static ref FOUNDATIONS_RE: Regex = Regex::new(format!(r"(?i)^\s*(foundations:)?\s*(((up\s*to\s*)?{}|empty)\s*(,\s*)?){}$", CARD_PATTERN, "{0,4}").as_str()).unwrap();
            static ref CARD_RE: Regex = Regex::new(format!(r"(?i){}", CARD_PATTERN).as_str()).unwrap();
        }
        if !FOUNDATIONS_RE.is_match(string) {
            return Err(format!("Could not parse foundations: \"{}\"", string))
        }
        let top_cards: Vec<Card> = CARD_RE.find_iter(string)
            .map(|re_match| re_match.as_str().parse().unwrap())
            .collect();
        let mut foundations = Foundations::new();
        for card in top_cards {
            if !foundations.foundation(card.suit).is_empty() {
                return Err(format!("Multiple foundations of suit {} specified", card.suit));
            } else {
                foundations.0[card.suit as usize] = card_sequence_up_to(card);
            }
        }
        Ok(foundations)
    }
fn from_str ( string : & str ) -> Result < Foundations , Self :: Err > { lazy_static ! { static ref FOUNDATIONS_RE Regex Regex new ( format ( r"(?i)^\s*(foundations:)?\s*(((up\s*to\s*)?{}|empty)\s*(,\s*)?){}$" CARD_PATTERN " " ) as_str ( ) ) unwrap ( ) static ref CARD_RE Regex Regex new ( format ( r"(?i){}" CARD_PATTERN ) as_str ( ) ) unwrap ( ) } if ! FOUNDATIONS_RE . is_match ( string ) { return Err ( format ! ( " \" \" " string ) ) } let top_cards : Vec < Card > = CARD_RE . find_iter ( string ) . map ( | re_match | re_match . as_str ( ) . parse ( ) . unwrap ( ) ) . collect ( ) ; let mut foundations = Foundations :: new ( ) ; for card in top_cards { if ! foundations . foundation ( card . suit ) . is_empty ( ) { return Err ( format ! ( " " card suit ) ) ; } else { foundations . 0 [ card . suit as usize ] = card_sequence_up_to ( card ) ; } } Ok ( foundations ) }
Converts a `&str` to `Foundations`.
Converts a ` &str ` to ` Foundations ` .
string
&str
string
&str
examples
None
use freecell::suit::{club, diamond, heart};
None
use freecell::{foundations, card, ace};


assert_eq!(
"4D 2H AC".parse(),
Ok(Foundations([
vec![Card { suit: Club, rank: ACE }],
Vec::new(),
vec![
Card { suit: Heart, rank: ACE },
Card { suit: Heart, rank: 2 },
],
vec![
Card { suit: Diamond, rank: ACE },
Card { suit: Diamond, rank: 2 },
Card { suit: Diamond, rank: 3 },
Card { suit: Diamond, rank: 4 },
],
]))
).

assert_eq!(
"6C 7S 9C".parse::(),
Err("Multiple foundations of suit Club specified".to_string())
);
```
assert_eq! ( " 4D 2H AC " . parse () Ok ( Foundations ( [ vec! [ Card { suit : Club rank : ACE } ] Vec :: new () vec! [ Card { suit : Heart rank : ACE } Card { suit : Heart rank : 2 } ] vec! [ Card { suit : Diamond rank : ACE } Card { suit : Diamond rank : 2 } Card { suit : Diamond rank : 3 } Card { suit : Diamond rank : 4 } ] ] )) ) . assert_eq! ( " 6C 7S 9C " . parse :: () Err ( " Multiple foundations of suit Club specified " . to_string () ) ) ; ` ` `