mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Remove recursion
This commit is contained in:
parent
d69d261999
commit
1767942e31
1 changed files with 15 additions and 27 deletions
|
@ -174,40 +174,28 @@ pub(crate) fn build_chain(args: &[(String, String)], filename: String) -> (PathB
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse {
|
macro_rules! parse {
|
||||||
($inner:expr, $args:expr, $filename:expr, $x:ident, $k:expr, $v:expr) => {{
|
($inner:expr, $x:ident, $k:expr, $v:expr) => {{
|
||||||
if let Some(processor) = parse::<$x>($k, $v) {
|
if let Some(processor) = parse::<$x>($k, $v) {
|
||||||
return build(
|
return (processor.path($inner.0), processor.command($inner.1));
|
||||||
(processor.path($inner.0), processor.command($inner.1)),
|
};
|
||||||
&$args[1..],
|
|
||||||
$filename,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(
|
let (path, args) =
|
||||||
inner: (PathBuf, Vec<String>),
|
args.into_iter()
|
||||||
args: &[(String, String)],
|
.fold((PathBuf::default(), vec![]), |inner, (name, value)| {
|
||||||
filename: String,
|
parse!(inner, Identity, name, value);
|
||||||
) -> (PathBuf, Vec<String>) {
|
parse!(inner, Thumbnail, name, value);
|
||||||
if args.len() == 0 {
|
parse!(inner, Resize, name, value);
|
||||||
return inner;
|
parse!(inner, Crop, name, value);
|
||||||
}
|
parse!(inner, Blur, name, value);
|
||||||
|
|
||||||
let (name, value) = &args[0];
|
debug!("Skipping {}: {}, invalid", name, value);
|
||||||
|
|
||||||
parse!(inner, args, filename, Identity, name, value);
|
inner
|
||||||
parse!(inner, args, filename, Thumbnail, name, value);
|
});
|
||||||
parse!(inner, args, filename, Resize, name, value);
|
|
||||||
parse!(inner, args, filename, Crop, name, value);
|
|
||||||
parse!(inner, args, filename, Blur, name, value);
|
|
||||||
|
|
||||||
debug!("Skipping {}: {}, invalid", name, value);
|
(path.join(filename), args)
|
||||||
|
|
||||||
build(inner, &args[1..], filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
build((PathBuf::default(), vec![]), args, filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_motion(s: &str) -> bool {
|
fn is_motion(s: &str) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue