Skip to main content

Answer

Struct Answer 

Source
pub struct Answer { /* private fields */ }
Expand description

A rule that judges a submitted answer. See the module documentation.

use shellgame::engine::answer::{exact, int, parts};

let rule = exact("navigator")
    .ignore_case()
    .mistake("toto není heslo", "To je obsah decoy.txt, ne password.txt.")
    .error("Heslo není správné.");
let both = parts(",", [int(3), exact("log.txt")]).format_message("Formát: počet,soubor");

Implementations§

Source§

impl Answer

Source

pub fn ignore_case(self) -> Self

Compare case-insensitively (Unicode lowercase on both sides).

Source

pub fn trim_trailing_slash(self) -> Self

After stripping whitespace, also drop trailing /, so delta/ counts as delta.

Source

pub fn mistake( self, key: impl Into<MistakeKey>, message: impl Into<String>, ) -> Self

A tailored message for one specific wrong answer. Text rules match it exactly after the rule’s normalization (strip, trailing slash, case folding); for int the key is an integer. Mistakes are checked before the correct answer and in the order declared.

Source

pub fn feedback(self, feedback: fn(&str) -> Option<String>) -> Self

Computed feedback for a wrong answer. It runs after literal mistakes and after the correct-answer check, receives the normalized answer (stripped, trailing slash trimmed if enabled, case as typed) and returns Some(message) to override the error text, or None to fall through to it.

Source

pub fn error(self, message: impl Into<String>) -> Self

The message for a wrong answer, instead of messages::INCORRECT. It must not reveal the answer.

Source

pub fn invalid(self, message: impl Into<String>) -> Self

The message when an int answer is not a number, instead of messages::EXPECTED_INTEGER.

Source

pub fn required(self, message: impl Into<String>) -> Self

The message when the player submits no answer at all, instead of messages::ANSWER_REQUIRED (messages::ANSWER_REQUIRED_NUMBER for int).

Source

pub fn format_message(self, message: impl Into<String>) -> Self

The message of a parts answer with the wrong number of parts, instead of messages::ANSWER_FORMAT. Not the same as Answer::error, which parts answers do not support: a wrong value is judged by the parts themselves.

Source

pub fn secret(self) -> Self

Mark the answer as a secret: the catalog lint then checks that it never appears in hints or in a shellgame submit <answer> example in the text.

Source

pub fn accepts<I, S>(self, examples: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Example answers that must be accepted. Checked by the catalog lint, never at run time; they document (and pin) what the rule means.

Source

pub fn rejects<I, S>(self, examples: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Example answers that must be rejected. Checked by the catalog lint.

Source

pub fn check(&self, ctx: &Ctx<'_>, answer: &str) -> Check

Judge an answer. Feedback is data: a wrong answer is Check::Fail(text).

Source

pub fn required_message(&self) -> &str

What to tell a player who submits nothing for a level that needs an answer.

Source

pub fn is_dynamic(&self) -> bool

True when the answer (or one of its parts) depends on the situation, so it cannot be known without a Ctx.

Source

pub fn is_secret(&self) -> bool

True when marked Answer::secret.

Source

pub fn static_answer(&self) -> Option<String>

One correct answer, as a player would type it, when it is known statically: the expected text, the first of one_of, the number, the suffix itself, the parts joined by the separator. None for exact_with (and anything containing it).

Source

pub fn accepted_examples(&self) -> &[String]

The accepts examples of this rule (not of its parts).

Source

pub fn rejected_examples(&self) -> &[String]

The rejects examples of this rule (not of its parts).

Source

pub fn nodes(&self) -> Vec<&Answer>

This answer and, recursively, every part of it.

Source

pub fn expected_texts(&self) -> Vec<String>

Every statically known correct answer in this tree (all accepted values, numbers, suffixes, each part’s, and the joined text of every parts rule).

Source

pub fn message_texts(&self) -> Vec<&str>

Every message this tree can show a player, apart from computed feedback.

Source

pub fn lint(&self) -> Vec<String>

Problems with how the rule was built: modifiers that do nothing, impossible rules.

Trait Implementations§

Source§

impl Clone for Answer

Source§

fn clone(&self) -> Answer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Answer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.