expression

Accept borrowed text when ownership is unnecessary

An inspection function should not require an owned String when it only needs to read text. A string slice accepts both a string literal and a borrowed String. Returning the byte length here is intentional; it is not the number of characters. Choose a narrower input type when it captures the true requirements. Expected result (NOT RUN): 4 3 still owned: book Common mistake: Taking String by value and forcing a caller to move or clone data for read-only inspection. Static Rust example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
fn label(text: &str) -> usize

Working Example

Example Snippetrust
fn byte_len(text: &str) -> usize { text.len() }fn main() {    let name = String::from("book");    println!("{} {}", byte_len(&name), byte_len("pen"));    println!("still owned: {name}");}
Rust Reference