trait

RangeBounds — accept multiple range forms

RangeBounds abstracts included, excluded and unbounded endpoints. It supports range forms such as .., a..b and a..=b. A range bound is not necessarily a finite iterator. Here contains checks a borrowed value against a generic range. Expected stdout (not executed): false true true Common mistake: Confusing an exclusive endpoint with an inclusive one. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
R: RangeBounds<T>; start_bound(); end_bound(); contains()

Working Example

Example Snippetrust
use std::ops::RangeBounds;fn includes(r: impl RangeBounds<i32>, x:i32)->bool { r.contains(&x) }fn main(){println!("{} {} {}",includes(1..4,4),includes(1..=4,4),includes(..,4));}
Rust Reference