Skip to main content

relate_core/
integer_args.rs

1//! The ADR-0175 integer-argument sites' authored texts.
2//!
3//! Written once so every layer that raises a site's rejection reads the
4//! same text: the planner's checks at plan time and, for the sites with a
5//! runtime coercion, the executor's argument coercion at run time. The
6//! slice bounds are plan-time only — their runtime coercion has no type
7//! rejection — and `SKIP` / `LIMIT` carry their own planner tokens.
8//! [`crate::FUNCTION_REQUIRES_ONE_ARGUMENT`] sets the precedent for a
9//! rejection spelling shared across layers.
10
11/// One integer-argument site's authored texts.
12pub struct IntegerArgSite {
13    /// The `InvalidArgumentType` detail of a non-numeric argument.
14    pub type_error: &'static str,
15    /// The site label a `NumberOutOfRange` rejection names. `None` where the
16    /// site has no runtime coercion to label: `range()`'s out-of-range
17    /// rejection (zero step, overflowing length) is authored in its executor,
18    /// not per argument.
19    pub range: Option<&'static str>,
20}
21
22/// A site that only gates the argument's type at plan time.
23const fn type_site(type_error: &'static str) -> IntegerArgSite {
24    IntegerArgSite {
25        type_error,
26        range: None,
27    }
28}
29
30/// A site whose runtime coercion raises `NumberOutOfRange`.
31const fn coercion_site(type_error: &'static str, range: &'static str) -> IntegerArgSite {
32    IntegerArgSite {
33        type_error,
34        range: Some(range),
35    }
36}
37
38pub const RANGE_START: IntegerArgSite = type_site("range() start");
39pub const RANGE_END: IntegerArgSite = type_site("range() end");
40pub const RANGE_STEP: IntegerArgSite = type_site("range() step");
41pub const SUBSTRING_START: IntegerArgSite =
42    coercion_site("substring() start must be an integer", "substring() start");
43pub const SUBSTRING_LENGTH: IntegerArgSite = coercion_site(
44    "substring() length must be an integer",
45    "substring() length",
46);
47pub const LEFT_LENGTH: IntegerArgSite =
48    coercion_site("left() length must be an integer", "left() length");
49pub const RIGHT_LENGTH: IntegerArgSite =
50    coercion_site("right() length must be an integer", "right() length");
51pub const LIST_INDEX: IntegerArgSite = type_site("list index must be an integer");
52pub const SLICE_START: IntegerArgSite = type_site("slice start must be an integer");
53pub const SLICE_END: IntegerArgSite = type_site("slice end must be an integer");