pub fn parse(&self, input: &str) -> Result<JsValue, JsError> {
        let result = parser::parse(self.state.clone(), input);
        match result {
            Ok(ok) => {
                let message = match ok {
                    ParsingResult::Look(msg) => JsMessage::Look(msg),
                    ParsingResult::Help(msg) => JsMessage::Help(msg),
                    ParsingResult::NewItem(msg) => JsMessage::NewItem(msg),
                    ParsingResult::DropItem(msg) => JsMessage::DropItem(msg),
                    ParsingResult::Inventory(msg) => JsMessage::Inventory(msg),
                    ParsingResult::SubjectNoEvent(msg) => JsMessage::SubjectNoEvent(msg),
                    ParsingResult::EventSuccess(event_msg) => JsMessage::EventSuccess(event_msg),
                    ParsingResult::Quit => JsMessage::NoOp,
                };
                Ok(JsValue::from_serde(&message).unwrap())
            }
            Err(err) => Err(JsError::new(&err.to_string())),
        }
    }
/// This is the main function that executes the game. Pass
/// the input string to this function and it will return
/// a result that can be used on the front-end to display
/// the game to the user.
/// Unlike the non-wasm version, this function will return
/// the result in JSON format. The conversion of the result
/// to JSON is done by the `JsValue::from_serde` function from
/// wasm_bindgen.
This is the main function that executes the game. Pass
the input string to this function and it will return
a result that can be used on the front-end to display
the game to the user.
Unlike the non-wasm version, this function will return
the result in JSON format. The conversion of the result
to JSON is done by the `JsValue::from_serde` function from
wasm_bindgen.
This is the main function that executes the game . Pass the input string to this function and it will return a result that can be used on the front - end to display the game to the user . Unlike the non - wasm version this function will return the result in JSON format . The conversion of the result to JSON is done by the ` JsValue :: from_serde ` function from wasm_bindgen .
pub fn parse(&self, input: &str) -> Result<JsValue, JsError> {
        let result = parser::parse(self.state.clone(), input);
        match result {
            Ok(ok) => {
                let message = match ok {
                    ParsingResult::Look(msg) => JsMessage::Look(msg),
                    ParsingResult::Help(msg) => JsMessage::Help(msg),
                    ParsingResult::NewItem(msg) => JsMessage::NewItem(msg),
                    ParsingResult::DropItem(msg) => JsMessage::DropItem(msg),
                    ParsingResult::Inventory(msg) => JsMessage::Inventory(msg),
                    ParsingResult::SubjectNoEvent(msg) => JsMessage::SubjectNoEvent(msg),
                    ParsingResult::EventSuccess(event_msg) => JsMessage::EventSuccess(event_msg),
                    ParsingResult::Quit => JsMessage::NoOp,
                };
                Ok(JsValue::from_serde(&message).unwrap())
            }
            Err(err) => Err(JsError::new(&err.to_string())),
        }
    }
pub fn parse ( & self , input : & str ) -> Result < JsValue , JsError > { let result = parser :: parse ( self . state . clone ( ) , input ) ; match result { Ok ( ok ) => { let message = match ok { ParsingResult :: Look ( msg ) => JsMessage :: Look ( msg ) , ParsingResult :: Help ( msg ) => JsMessage :: Help ( msg ) , ParsingResult :: NewItem ( msg ) => JsMessage :: NewItem ( msg ) , ParsingResult :: DropItem ( msg ) => JsMessage :: DropItem ( msg ) , ParsingResult :: Inventory ( msg ) => JsMessage :: Inventory ( msg ) , ParsingResult :: SubjectNoEvent ( msg ) => JsMessage :: SubjectNoEvent ( msg ) , ParsingResult :: EventSuccess ( event_msg ) => JsMessage :: EventSuccess ( event_msg ) , ParsingResult :: Quit => JsMessage :: NoOp , } ; Ok ( JsValue :: from_serde ( & message ) . unwrap ( ) ) } Err ( err ) => Err ( JsError :: new ( & err . to_string ( ) ) ) , } }
This is the main function that executes the game.
This is the main function that executes the game .
&self
input
&str
&self
input
&str