Skip to main content

floria_plugin_sdk/errors/
arguments.rs

1use super::super::*;
2
3/// Exact arguments.
4pub fn arguments_exact(required: usize, actual: usize) -> DispatchError {
5    format!("must have {}: |error|{}|", argument(required), actual)
6}
7
8/// Minimum arguments.
9pub fn arguments_min(min: usize, actual: usize) -> DispatchError {
10    format!("must have at least {}: |error|{}|", argument(min), actual)
11}
12
13/// Minimum arguments.
14pub 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}