floria_plugin_sdk/errors/
arguments.rs1use super::super::*;
2
3pub fn arguments_exact(required: usize, actual: usize) -> DispatchError {
5 format!("must have {}: |error|{}|", argument(required), actual)
6}
7
8pub fn arguments_min(min: usize, actual: usize) -> DispatchError {
10 format!("must have at least {}: |error|{}|", argument(min), actual)
11}
12
13pub fn arguments_range(min: usize, max: usize, actual: usize) -> DispatchError {
15 if min == 0 {
16 format!("must have at most {}: |error|{}|", argument(min), actual)
17 } else {
18 format!("must have at between {} and {}: |error|{}|", count_to_string(min), argument(max), actual)
19 }
20}
21
22fn argument(count: usize) -> DispatchError {
23 let string = count_to_string(count);
24 if count == 1 { format!("{} argument", string) } else { format!("{} arguments", string) }
25}
26
27fn count_to_string(count: usize) -> DispatchError {
28 match count {
29 0 => "no".to_string(),
30 _ => count.to_string(),
31 }
32}