1use crate::{AsIter, Value};
2use std::collections::HashMap;
3
4pub trait Argument<const CONST: bool> {
5 type Value: Value<CONST>;
6
7 fn name(&self) -> &str;
8 fn value(&self) -> &Self::Value;
9}
10
11pub trait ConstArgument: Argument<true> {}
12pub trait VariableArgument: Argument<false> {}
13
14impl<T: Argument<true>> ConstArgument for T {}
15impl<T: Argument<false>> VariableArgument for T {}
16
17pub trait Arguments<const CONST: bool>: AsIter<Item = Self::Argument> {
18 type Argument: Argument<CONST>;
19
20 fn equivalent(optional_self: Option<&Self>, optional_other: Option<&Self>) -> bool {
21 let lhs: HashMap<&str, _> = optional_self
22 .map(|args| {
23 HashMap::from_iter(args.iter().map(|arg| (arg.name(), arg.value().as_ref())))
24 })
25 .unwrap_or_default();
26 let rhs: HashMap<&str, _> = optional_other
27 .map(|args| {
28 HashMap::from_iter(args.iter().map(|arg| (arg.name(), arg.value().as_ref())))
29 })
30 .unwrap_or_default();
31 lhs == rhs
32 }
33}
34
35pub trait ConstArguments: Arguments<true> {}
36pub trait VariableArguments: Arguments<false> {}
37
38impl<T: Arguments<true>> ConstArguments for T {}
39impl<T: Arguments<false>> VariableArguments for T {}