use anyhow::{Result, anyhow, bail};
use super::numeric::IntWidth;
pub(super) trait Args {
fn text(&self, i: usize) -> String;
fn int(&self, i: usize) -> Option<i64>;
fn float(&self, i: usize) -> Option<f64>;
fn pattern_chars(&self, i: usize) -> Option<Vec<char>>;
}
fn int_arg(args: &impl Args, i: usize) -> Result<i64> {
match args.int(i) {
Some(n) => Ok(n),
None => bail!("expected an integer argument"),
}
}
fn usize_arg(args: &impl Args, i: usize) -> Result<usize> {
let n = int_arg(args, i)?;
usize::try_from(n).map_err(|_| anyhow!("`{n}` is not a valid count"))
}
pub(super) fn usize_i64(i: usize) -> i64 {
i64::try_from(i).expect("value exceeds i64")
}
pub(super) fn usize_value(i: usize) -> super::value::Value {
super::value::Value::int_of_width(i128::from(usize_i64(i)), IntWidth::USize)
}
fn float_arg(args: &impl Args, i: usize) -> Result<f64> {
match args.float(i) {
Some(f) => Ok(f),
None => bail!("expected a float argument"),
}
}
mod json;
mod numbers;
mod regex;
mod scalars;
mod text;
mod time;
pub(crate) use json::*;
pub(crate) use numbers::*;
pub(crate) use regex::*;
pub(crate) use scalars::*;
pub(crate) use text::*;
pub(crate) use time::*;