std-method

LinkedList::contains

Check membership by comparing stored elements against the query. A linked list has no hash index, so a search may visit every node. Expected stdout (not executed): true false Common mistake: Expecting constant-time membership checks.

Formal Syntax & Structure

rust syntaxrust
fn contains(&self, x: &T) -> bool where T: PartialEq

Working Example

Example Snippetrust
fn main() {    use std::collections::LinkedList;    let q = LinkedList::from(["draft", "ready"]);    println!("{} {}", q.contains(&"ready"), q.contains(&"sent"));}
Rust Reference