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: SpeedSpeed 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: StringSnake 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: StringSnake 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: u16Initial length of the snake
life: u16Number of lives
nb_of_fruits: u16Number of fruits in the game
no_caps_fps: boolModern 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: boolAs default is false, order is more logical
no_classic_mode: bool§load: Option<u16>Load game parameters
Implementations§
Source§impl GameOptions
impl GameOptions
Sourcepub fn initial_position() -> Position
pub fn initial_position() -> Position
Returns the initial snake position
pub fn emojis_with_news_line() -> String
pub fn emojis_iterator() -> impl Iterator<Item = String>
Sourcepub fn to_structured_toml(&self) -> Table
pub fn to_structured_toml(&self) -> Table
Sourcepub fn validate(&mut self)
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
Sourcepub fn load_from_toml_preset(preset: u16) -> Result<Self>
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.
Sourcefn load_from_toml<P: AsRef<Path>>(path: P) -> Result<Self>
fn load_from_toml<P: AsRef<Path>>(path: P) -> Result<Self>
Sourcepub fn save_to_toml_preset(&mut self, preset: u16) -> Result<()>
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.
Trait Implementations§
Source§impl ActionParameter for GameOptions
impl ActionParameter for GameOptions
Source§impl Args for GameOptions
impl Args for GameOptions
Source§fn group_id() -> Option<Id>
fn group_id() -> Option<Id>
ArgGroup::id][crate::ArgGroup::id] for this set of argumentsSource§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command] so it can instantiate self via
[FromArgMatches::update_from_arg_matches_mut] Read moreSource§impl Clone for GameOptions
impl Clone for GameOptions
Source§fn clone(&self) -> GameOptions
fn clone(&self) -> GameOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CommandFactory for GameOptions
impl CommandFactory for GameOptions
Source§impl Debug for GameOptions
impl Debug for GameOptions
Source§impl Default for GameOptions
impl Default for GameOptions
Source§fn default() -> GameOptions
fn default() -> GameOptions
Source§impl<'de> Deserialize<'de> for GameOptionswhere
GameOptions: Default,
impl<'de> Deserialize<'de> for GameOptionswhere
GameOptions: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromArgMatches for GameOptions
impl FromArgMatches for GameOptions
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Parser for GameOptions
impl Parser for GameOptions
§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
§fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
Auto Trait Implementations§
impl Freeze for GameOptions
impl RefUnwindSafe for GameOptions
impl Send for GameOptions
impl Sync for GameOptions
impl Unpin for GameOptions
impl UnwindSafe for GameOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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