fn flush(&mut self) -> Result<(), ParsingError> {
        // Replace the old state with the `Flushed` state.
        match mem::replace(&mut self.state, ParserState::Flushed) {
            // The global settings are written directly to the deck; nothing to flush.
            ParserState::GlobalSettings => (),
            // TODO: Get rid of the hack `tag != ""` and detect overwritten settings for the
            //       default tag as well. It is important to use `&` and not `&&` to avoid
            //       short-circuiting.
            // Insert the new tag settings.
            ParserState::TagSettings(tag) => if (tag != "") & self.deck.tag_settings
                // Swap the current settings with the default settings.
                .insert(tag, mem::replace(&mut self.current_tag_settings, self.deck.default_tag_settings()))
                .is_some() {
                    // Throw an error if the settings already exist in the deck.
                    return Err(ParsingError::Other("configuring a tag multiple times (previous section)"));
                },
            // Insert the card.
            ParserState::Card(id) => if self.deck.cards
                // Swap the current card with a default, empty card.
                // TODO: Get rid of this clone.
                .insert(id.clone(), {
                    let mut card = mem::replace(&mut self.current_card, Default::default());
                    // If no files were specified for the card, default to its ID with a `.pdf`
                    // extension.
                    if card.view.is_empty() {
                        // Add the path to the list of files.
                        card.view.push(cards::View::Pdf(format!("{}.pdf", id)));
                    }

                    card
                })
                .is_some() {
                    // Throw an error if the card already exists in the deck.
                    return Err(ParsingError::Other("the same card ID appears multiple times"));
                },
            // Already flushed; do nothing.
            ParserState::Flushed => (),
        }

        Ok(())
    }
/// Flush changes.
///
/// This ought to be called after sections have been completed and in the end of the file.
Flush changes.
This ought to be called after sections have been completed and in the end of the file.
Flush changes . This ought to be called after sections have been completed and in the end of the file .
fn flush(&mut self) -> Result<(), ParsingError> {
        // Replace the old state with the `Flushed` state.
        match mem::replace(&mut self.state, ParserState::Flushed) {
            // The global settings are written directly to the deck; nothing to flush.
            ParserState::GlobalSettings => (),
            // TODO: Get rid of the hack `tag != ""` and detect overwritten settings for the
            //       default tag as well. It is important to use `&` and not `&&` to avoid
            //       short-circuiting.
            // Insert the new tag settings.
            ParserState::TagSettings(tag) => if (tag != "") & self.deck.tag_settings
                // Swap the current settings with the default settings.
                .insert(tag, mem::replace(&mut self.current_tag_settings, self.deck.default_tag_settings()))
                .is_some() {
                    // Throw an error if the settings already exist in the deck.
                    return Err(ParsingError::Other("configuring a tag multiple times (previous section)"));
                },
            // Insert the card.
            ParserState::Card(id) => if self.deck.cards
                // Swap the current card with a default, empty card.
                // TODO: Get rid of this clone.
                .insert(id.clone(), {
                    let mut card = mem::replace(&mut self.current_card, Default::default());
                    // If no files were specified for the card, default to its ID with a `.pdf`
                    // extension.
                    if card.view.is_empty() {
                        // Add the path to the list of files.
                        card.view.push(cards::View::Pdf(format!("{}.pdf", id)));
                    }
                    card
                })
                .is_some() {
                    // Throw an error if the card already exists in the deck.
                    return Err(ParsingError::Other("the same card ID appears multiple times"));
                },
            // Already flushed; do nothing.
            ParserState::Flushed => (),
        }
        Ok(())
    }
fn flush ( & mut self ) -> Result < ( ) , ParsingError > { // Replace the old state with the `Flushed` state. match mem :: replace ( & mut self . state , ParserState :: Flushed ) { // The global settings are written directly to the deck; nothing to flush. ParserState :: GlobalSettings => ( ) , // TODO: Get rid of the hack `tag != ""` and detect overwritten settings for the //       default tag as well. It is important to use `&` and not `&&` to avoid //       short-circuiting. // Insert the new tag settings. ParserState :: TagSettings ( tag ) => if ( tag != " " ) & self . deck . tag_settings // Swap the current settings with the default settings. . insert ( tag , mem :: replace ( & mut self . current_tag_settings , self . deck . default_tag_settings ( ) ) ) . is_some ( ) { // Throw an error if the settings already exist in the deck. return Err ( ParsingError :: Other ( " " ) ) ; } , // Insert the card. ParserState :: Card ( id ) => if self . deck . cards // Swap the current card with a default, empty card. // TODO: Get rid of this clone. . insert ( id . clone ( ) , { let mut card = mem :: replace ( & mut self . current_card , Default :: default ( ) ) ; // If no files were specified for the card, default to its ID with a `.pdf` // extension. if card . view . is_empty ( ) { // Add the path to the list of files. card . view . push ( cards :: View :: Pdf ( format ! ( " " id ) ) ) ; } card } ) . is_some ( ) { // Throw an error if the card already exists in the deck. return Err ( ParsingError :: Other ( " " ) ) ; } , // Already flushed; do nothing. ParserState :: Flushed => ( ) , } Ok ( ( ) ) }
Flush changes.
Flush changes .
&mut self
&mut self