GameOptions

Struct GameOptions 

Source
pub struct GameOptions {
    pub speed: Speed,
    pub head_symbol: String,
    pub body_symbol: String,
    pub snake_length: u16,
    pub life: u16,
    pub nb_of_fruits: u16,
    no_caps_fps: bool,
    pub caps_fps: bool,
    pub classic_mode: bool,
    no_classic_mode: bool,
    pub load: Option<u16>,
}
Expand description

Structure holding all the configuration parameters for the game

Fields§

§speed: Speed

Speed of the snake (Slow, Normal, Fast, Crazy) Derives ValueEnum on the enum Speed and enforces the type clap::ValueEnum, which automatically handles possible values and displays them in the help message. Now, clap enforces valid inputs without requiring a manual FromStr implementation.

§head_symbol: String

Snake symbol (emoji or character) Defines short value because doublon, as short and long, are by default based on the name of the variable Default is Christmas tree

§body_symbol: String

Snake trail symbol (emoji or character) need to operate over graphene not chars see https://crates.io/crates/unicode-segmentation/ / Or deep explanation:https://docs.rs/bstr/1.12.0/bstr/#when-should-i-use-byte-strings Default is snow emoji

§snake_length: u16

Initial length of the snake

§life: u16

Number of lives

§nb_of_fruits: u16

Number of fruits in the game

§no_caps_fps: bool

Modern way to do CLI, two dedicated flag to set/unset the value, beginning with –no- (for false) UX better than –feature false / –feature true, better than default (no flag = false). If you want the possibility to set both values, as no clear default value or want to be able to easily programmatically change the value (as there) or to have a default at true


See: https://jwodder.github.io/kbits/posts/clap-bool-negate/ As default is true, no and value are swaped

§caps_fps: bool§classic_mode: bool

As default is false, order is more logical

§no_classic_mode: bool§load: Option<u16>

Load game parameters

Implementations§

Source§

impl GameOptions

Source

pub fn initial_position() -> Position

Returns the initial snake position

Source

pub fn emojis_with_news_line() -> String

Source

pub fn emojis_iterator() -> impl Iterator<Item = String>

Source

pub fn to_structured_toml(&self) -> Table

To be editable easily

§Panics

if self cannot be parsed (not possible)

Source

pub fn validate(&mut self)

Validates and clamps the parameters to their allowed ranges. Ensures that numeric values are within the bounds defined in the CLI macro and that symbols are exactly one grapheme long. Enums are already checked automatically during deserialization

Source

pub fn load_from_toml_preset(preset: u16) -> Result<Self>

Load parameters from a preset TOML configuration

§Errors

Returns an error if the preset file cannot be opened or read, or if it contains invalid TOML.

Source

fn load_from_toml<P: AsRef<Path>>(path: P) -> Result<Self>

Load parameters from a TOML file

§Errors

Returns an error if the file cannot be opened or read.

§Panics

Panic if the file contents cannot be deserialized as valid TOML.

Source

pub fn save_to_toml_preset(&mut self, preset: u16) -> Result<()>

Save parameters to a preset TOML configuration

§Errors

Returns an error if the preset file cannot be created or written to.

Source

fn save_to_toml<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Save the current parameters to a TOML file NB: non-serializable parameters are marked skip with serde annotation and will not be included

§Errors

Returns an error if the file cannot be created or written to.

§Panics

Panics if the game parameters cannot be serialized to TOML.

Trait Implementations§

Source§

impl ActionParameter for GameOptions

Source§

fn apply_and_save(&mut self, rows: &[RowData], current_preset: Option<u16>)

Source§

impl Args for GameOptions

Source§

fn group_id() -> Option<Id>

Report the [ArgGroup::id][crate::ArgGroup::id] for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to [Command] so it can instantiate Self via [FromArgMatches::from_arg_matches_mut] Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to [Command] so it can instantiate self via [FromArgMatches::update_from_arg_matches_mut] Read more
Source§

impl Clone for GameOptions

Source§

fn clone(&self) -> GameOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CommandFactory for GameOptions

Source§

fn command<'b>() -> Command

Build a [Command] that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a [Command] that can update self. Read more
Source§

impl Debug for GameOptions

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for GameOptions

Source§

fn default() -> GameOptions

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for GameOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromArgMatches for GameOptions

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for GameOptions

§

fn parse() -> Self

Parse from std::env::args_os(), [exit][Error::exit] on error.
§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, [exit][Error::exit] on error.
§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, [exit][Error::exit] on error. Read more
§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.
Source§

impl Serialize for GameOptions

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

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

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,