expression
REST: validate page-size bounds
Limit how much data one list request can ask for. The API contract must specify its own handling of zero and excessive limits. This API rejects values outside 1–100 rather than silently clamping them. A size bound does not itself control request frequency or query complexity. Standalone synthetic example. Expected stdout (not executed): 0: false 20: true 101: false Common mistake: Confusing a page-size limit with a rate limit.
Formal Syntax & Structure
rust syntaxrust
1 <= limit && limit <= 100Working Example
Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() { fn validate(limit: usize) -> Result<usize, &'static str> { if (1..=100).contains(&limit) { Ok(limit) } else { Err("invalid limit") } } for limit in [0, 20, 101] { println!("{limit}: {}", validate(limit).is_ok()); }}