expression
REST: validate a correlation identifier
Correlation identifiers help connect diagnostic records. Apply a local length and character policy before accepting a supplied identifier. A valid-looking identifier is still untrusted and must not serve as a credential. The exact alphabet here is an illustrative service policy. Standalone synthetic example. Expected stdout (not executed): true false false false Common mistake: Logging arbitrary client-provided strings without validation or redaction.
Formal Syntax & Structure
rust syntaxrust
value.len() <= 64 && value.bytes().all(...)Working 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 acceptable(s: &str) -> bool { !s.is_empty() && s.len() <= 64 && s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_') } for value in ["req-17", "", "bad value", "line\nbreak"] { println!("{}", acceptable(value)); }}