Struct forne::Driver

source ·
pub struct Driver<'e, 's> { /* private fields */ }
Expand description

A system to drive user interactions forward by providing a re-entrant polling architecture. The caller should call .next() to get the next question/answer pair, providing the user’s response for the previous question so the driver can update the set as necessary. This architecture allows the caller much greater control over the order of execution and display than an interface type opaquely driven by this library would.

Implementations§

source§

impl<'e, 's> Driver<'e, 's>

source

pub fn set_target(&mut self, target: CardType) -> &mut Self

Sets a specific type of card that this driver will exclusively target. By default, drivers target all cards.

source

pub fn set_max_count(&mut self, count: u32) -> &mut Self

Sets a maximum number of elements to be reviewed through this driver. This can be useful for long-term learning, in which you only want to review, say, 30 cards per day.

Obviously, if there are not enough cards to reach this maximum count, the driver will stop before the count is reached, and will not go back to the beginning.

source

pub fn no_mark_starred(&mut self) -> &mut Self

If this driver is being used to run a test, prevents cards the user gets wrong from being automatically starred.

source

pub fn no_mark_unstarred(&mut self) -> &mut Self

If this driver is being used to run a test, prevents cards the user gets right from being unstarred if they were previously starred.

This is especially useful when there are a small number of cards that the user is getting wrong consistently, which they want to continue keeping track of, while also still reviewing them many times.

source

pub fn no_mutate_difficulty(&mut self) -> &mut Self

If this driver is being used to run a learning session, prevents the learning method from marking cards as difficult, or from downgrading cards currently marked as difficult to no longer difficult.

Since the difficult metadatum is almost entirely internal, there are generally very few scenarios in which this behaviour is desired.

source

pub fn get_count(&self) -> u32

Gets the number of cards that have been reviewed by this driver so far.

source

pub fn first(&mut self) -> Result<Option<SlimCard>>

Gets the first question/answer pair of this run. While it is perfectly safe to run this at any time, it is semantically nonsensical to run this more than once, as Forn’s internals will become completely useless. If you want to display each card to the user only once, irrespective of the metadata attached to it, you should instantiate the driver for a test, rather than a learning session.

This will return None if there are no more cards with non-zero weightings, in which case the learn or test session described by this driver is complete. (If progress is not cleared, this could easily happen with a .first() call.)

This will automatically continue the most recent session of either learning or testing, if there is one.

source

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

Provides the allowed responses for this learn method (or for the test, if this driver is being used for a test), in the order they were defined. The argument to .next() must be an element in the list this returns.

source

pub fn next(&mut self, response: String) -> Result<Option<SlimCard>>

Gets the next question/answer pair, given a response to the last question/answer. If this is the first, you should call .first() instead, as calling this will lead to an error. Note that the provided response must be identical to one of the responses defined by the method in use (these can be found with .allowed_responses()).

source

pub fn save_set_to_json(&self) -> Result<String>

Saves the underlying set to JSON. This should generally be called between each presentation of a card to ensure the user does not lose their progress.

Auto Trait Implementations§

§

impl<'e, 's> !RefUnwindSafe for Driver<'e, 's>

§

impl<'e, 's> Send for Driver<'e, 's>

§

impl<'e, 's> Sync for Driver<'e, 's>

§

impl<'e, 's> Unpin for Driver<'e, 's>

§

impl<'e, 's> !UnwindSafe for Driver<'e, 's>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V