Skip to content

Commit

Permalink
Fix extracting duration from string
Browse files Browse the repository at this point in the history
  • Loading branch information
WilfSilver authored and elkowar committed Dec 20, 2023
1 parent fe245c7 commit cac553e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions crates/eww/src/window_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ use yuck::{
value::Coords,
};

pub fn extract_value_from_args(name: &str, args: &mut HashMap<VarName, DynVal>) -> Option<DynVal> {
args.remove(&VarName(name.to_string()))
}

fn parse_value_from_args<T: FromStr>(name: &str, args: &mut HashMap<VarName, DynVal>) -> Result<Option<T>, T::Err> {
extract_value_from_args(name, args).map(|x| FromStr::from_str(&x.as_string().unwrap())).transpose()
args.remove(&VarName(name.to_string())).map(|x| FromStr::from_str(&x.as_string().unwrap())).transpose()
}

/// This stores the arguments given in the command line to create a window
Expand Down Expand Up @@ -45,7 +41,7 @@ impl WindowArguments {
size: parse_value_from_args::<Coords>("size", &mut args)?,
monitor: parse_value_from_args::<MonitorIdentifier>("screen", &mut args)?,
anchor: parse_value_from_args::<AnchorPoint>("anchor", &mut args)?,
duration: extract_value_from_args("duration", &mut args)
duration: parse_value_from_args::<DynVal>("duration", &mut args)?
.map(|x| x.as_duration())
.transpose()
.context("Not a valid duration")?,
Expand Down

0 comments on commit cac553e

Please sign in to comment.