expression
Expose a borrowed lazy domain query instead of a temporary collection
An iterator-returning API can let callers choose whether to count, search, or collect matching values. Its borrowed items remain tied to the source. This query filters active users and exposes only their names; it does not allocate a new vector unless the caller collects. Expected result (NOT RUN): first: Some("Ada") count: 1 Common mistake: Returning references to a temporary vector or collecting eagerly when a caller only needs one item. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
fn active_names(&self) -> impl Iterator<Item = &str> + '_Working Example
Example Snippetrust
struct User { name: String, active: bool }struct Directory(Vec<User>);impl Directory { fn active_names(&self) -> impl Iterator<Item = &str> + '_ { self.0.iter().filter(|u| u.active).map(|u| u.name.as_str()) }}fn main() { let directory = Directory(vec![User { name: "Ada".into(), active: true }, User { name: "Lin".into(), active: false }]); println!("first: {:?}", directory.active_names().next()); println!("count: {}", directory.active_names().count());}