The tension in the North Pole Dev room had not dissipated. Santa’s absence loomed large, and Blitzen had clearly let the power go to his antlers. The elves were beginning to mutter about mutiny—especially after Blitzen had loudly declared that grep was overrated and "real devs" write their own search tools.
“We need a better log system,” Blitzen announced, pacing in front of the DevOps board like a caffeinated startup founder. “I’m tired of manually combing through logs! It’s time we automate this.”
Prancer peeked up from their desk. “Can’t we just pipe the logs into grep
like everyone else?”
Blitzen’s glare could have melted the polar ice caps. “Prancer, if you’re going to suggest mediocre solutions, you can go back to working in Node.js.”
Prancer recoiled, whispering, “Too far, Blitzen. Too far.”
Blitzen wanted a log search tool so advanced that even Santa would call it “blitzening fast.” Logs were piling up from every North Pole subsystem—Toy Tracker 3000, SleighOS, and even Reindeer AI. The elves needed to find specific entries without scrolling for hours.
“You!” Blitzen pointed at Frostbyte, the elf known for typing faster than a Model M keyboard. “You’re going to write a LogQuery
struct in Rust that can search through our logs.”
Frostbyte cracked his knuckles, opened NeoVim, and got to work.
But he needs your help to be saved from Blitzen’s sass and implement the LogQuery
struct with its search
method?
Here’s what Frostbyte must implement:
String
logs.new
that accepts a reference to a Vec<String>
and returns a LogQuery
.search
that:
Vec
of references to strings containing the keyword
.keyword
must be handled properly.If you're stuck or need a starting point, here are some hints to help you along the way!
Your LogQuery
struct will likely hold a &'a Vec<String>
.
The new
function should accept a reference to a &'a Vec<String>
and return a LogQuery
.
The search
method should accept a &self
and a keyword: &str
parameter.
To return references to the logs, you can use -> Vec<&'a String>
Implement search
by iterating over self.logs
. e.g. self.logs.iter()
Use filter
and provide a closure. e.g. filter(|log| {})
Use contains
to check if a log contains the keyword
. e.g. log.contains(keyword)
Use collect
to convert the iterator back to a Vec
. e.g. collect::<Vec<_>>()
omar-s-ta
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { LogQuery { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<_>>() }}
jgpaiva
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, q: &str) -> Vec<&String> { let mut retval = Vec::new(); for s in self.logs { if s.contains(q) { retval.push(s); } } retval }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
mliertzer
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn new(logs: &'a Vec<String>) -> Self { Self{logs} }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs .iter() .filter(|line| {line.contains(keyword)}) .collect() }}
isaaclv
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a>{ pub fn new(input: &'a Vec<String>) -> Self { Self { logs: input } } pub fn search(&self, key: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(key)).collect::<Vec<_>>() }} // 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
whereswald0
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery { logs: logs, } } // // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and // returns a vector of references to those logs. pub fn search(&self, slice: &str) -> Vec<&str> { let mut found: Vec<&str> = Vec::new(); for log in self.logs { if log.as_str().contains(slice) { found.push(log); } } return found; }}
terminox
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery { logs: logs } } pub fn search(&self, slice: &str) -> Vec<&str> { let mut found: Vec<&str> = Vec::new(); for log in self.logs { if log.as_str().contains(slice) { found.push(log); } } return found; }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
mei28
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } } pub fn search(&self, query: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(query)).collect() }}
kapaseker
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, query: &str) -> Vec<&String> { self.logs.iter().filter(|&l| l.contains(query)).collect() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
pilotso11
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a>{ // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String> ) -> Self { Self { logs } } // // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and // returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&str> { self.logs.iter().filter(|log| log.contains(keyword)).map(|log| log.as_str()).collect() }}
hagl
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self{ logs } } pub fn search(&self, query: &str) -> Vec<&'a str> { self.logs.iter().filter(|l| l.contains(query)).map(|e| e.as_str()).collect() } }// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
mladen5000
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&String> { let matches = self .logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<_>>(); matches }}
doroshtapgh
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(keyword)).collect::<Vec<_>>() }}
chokkoyamada
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQuery// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { LogQuery { logs } } pub fn search(&self, query: &str) -> Vec<&str> { self.logs .iter() .filter(|log| log.contains(query)) .map(|log| log.as_str()) .collect() }}
Ankit8848
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a>{// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &'a str) -> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(keyword)).collect() }}
habu1010
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(keyword)).collect::<Vec<_>>() }}
rjensen
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and // returns a vector of references to those logs. pub fn search(&self, search_term: &'a str) -> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(search_term)).collect() }}
BetkeJ
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQuery// 2. Create a public associated function named `new()` that will take a reference to a vector of stringsimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs: logs, } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, query: &str) -> Vec<&str> { let mut result: Vec<&str> = vec![]; for log in self.logs.iter() { if log.find(query) != None { result.push(&log); } } result }}
json-stateham
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, term: &'a str) -> Vec<&'a String> { self.logs.iter().filter(|log| { log.contains(term) }).collect::<Vec<_>>() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
nanannnnnn
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(log: &'a Vec<String>) -> Self { Self { logs: log } } pub fn search(&self, keyword: &str) -> Vec<&String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect() }}
arm01846
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'_> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery{ logs: logs } } pub fn search(&self, keyword: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(keyword)).collect::<Vec<&String>>() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
MCsamurai034
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new( logs: &'a Vec<String> ) -> Self { LogQuery { logs, } }// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn search( &self , keyword: &str) -> Vec<&str> { let mut vec: Vec<&str> = Vec::new(); for l in self.logs { if l.contains(keyword){ vec.push(l.as_str()); } } return vec }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.}
MCsamurai034
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new( logs: &'a Vec<String> ) -> Self { LogQuery { logs, } }// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn search( &self , keyword: &str) -> Vec<&String> { let mut vec: Vec<&String> = Vec::new(); for l in self.logs { if l.contains(keyword){ vec.push(&l); } } return vec }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.}
MCsamurai034
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new( logs: &'a Vec<String> ) -> Self { LogQuery { logs, } }// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn search( &self , keyword: &str) -> Vec<&String> { let logs: &Vec<String> = self.logs; let mut vec: Vec<&String> = Vec::new(); for l in logs { if l.contains( keyword ){ vec.push(&l); } } return vec }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.}
ankeetparikh
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQuery// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, pattern: &str) -> Vec<&String> { self.logs.iter() .filter(|x| x.contains(&pattern)) .collect() }}
Tarokc
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery { Self { logs, } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| {log.contains(keyword)}).collect::<Vec<_>>() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
eguefif
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self{ Self { logs, } } pub fn search(&self, keyword: &str) -> Vec<&str>{ let mut retval = Vec::new(); for entry in self.logs { if let Some(_) = entry.find(keyword){ retval.push(entry.as_str()) } } retval }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
Nismirno
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter() .filter(|log| { log.contains(keyword) }) .collect::<Vec<_>>() }}
uRTLy
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&String> { let mut hits: Vec<&String> = vec![]; for log in self.logs { if let Some(_) = log.find(keyword) { hits.push(log); } } hits }}
franlopezm
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter() .filter(|log| log.contains(keyword)) .collect() }}
franlopezm
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| { log.contains(keyword) }).collect() }}
arilet
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(v: &'a Vec<String>) -> Self { LogQuery { logs: v } } // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and returns a vector of references to those logs. pub fn search(&self, s: &str) -> Vec<&String> { self.logs.iter().filter(|x| x.contains(s)).collect() }}
MaoX-Yu
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| { log.contains(keyword) }).collect() }}
felipesaruhashi
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl <'a>LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self{logs: logs} } pub fn search(&self, keyword: &str) -> Vec<&'a String> { (*self).logs.iter().filter(|log| {log.contains(keyword)}).collect::<Vec<&String>>() }} // 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
tamanishi
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl <'a>LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self{logs: logs} } pub fn search(&self, keyword: &str) -> Vec<&'a String> { (*self).logs.iter().filter(|log| {log.contains(keyword)}).collect::<Vec<&String>>() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
hafihaf123
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, string: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(string)) .collect() }}
hafihaf123
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, string: &str) -> Vec<&'a String> { let mut references = Vec::new(); for log in self.logs { if log.contains(string) { references.push(log); } } references }}
gmvar
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery{ logs, } } // 3. Create a public method named `search` that accepts a string slice and finds it from the logs and // returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&'a String> { return self.logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<_>>(); }}
rirze
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings// pub fn new(strings: &'a Vec<String>) -> Self { Self { logs: strings } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, to_find: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| { log.contains(to_find) }).collect() }}
KLcpb
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a>{ pub fn new(vec: &Vec<String>) -> LogQuery{ LogQuery{logs:vec} } pub fn search(&self,keyword: &str)->Vec<&String>{ self.logs.iter() .filter(|s| s.contains(keyword) ) .collect() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
iamsahu
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'_> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a>{ LogQuery { logs } } pub fn search(&self, query: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(query)).collect() }}
iamsahu
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'_> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a>{ LogQuery { logs } } pub fn search(&self, query: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(query)).collect() }}
kanakshilledar
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } } // 3. Create a public method named `search` pub fn search(&self, keyword: &str) -> Vec<&String> { // Filter logs that contain the keyword and collect references self.logs .iter() .filter(|log| log.contains(keyword)) .collect() }}
phate45
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQuery// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { return Self { logs } } pub fn search(&self, query: &str) -> Vec<&'a String> { let mut res = vec![]; for q in self.logs { if q.contains(query) { res.push(q); } } res }}
sarub0b0
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str ) -> Vec<&'a String> { self.logs.iter().filter(|s| s.contains(keyword)).collect() }}
wlabranche
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| { log.contains(keyword) }).collect::<Vec<_>>() }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
RedNapPanda
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &'a str) -> Vec<&'a String> { self.logs.iter().filter(|s| s.contains(keyword)).collect::<Vec<_>>() }}
galenseilis
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl <'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, keyword: &str) -> Vec<&String> { return self .logs .iter() .filter(|log| log.contains(&keyword)) .collect::<Vec<_>>() } }
arcnemesys
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new (logs: &'a Vec<String>) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { let matches: Vec<&'a String> = self.logs .iter() .filter(|log| log.contains(keyword)).collect(); matches }}// 2. Create a public associated function named `new()` that will take a reference to a vector of strings//// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs.
lulingar
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> {// 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { Self { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(&self, string: &str) -> Vec<&'a String> { self.logs.iter() .filter(|entry| entry.contains(string)) .collect() }}
jsdm13
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { // 2. Create a public associated function named `new()` that will take a reference to a vector of strings pub fn new(logs: &'a Vec<String>) -> Self { LogQuery { logs } }// 3. Create a public method named `search` that accepts a string slice and finds it from the logs and// returns a vector of references to those logs. pub fn search(self, key: &'a str) -> Vec<&String> { self.logs .iter() .filter(|log| log.contains(key)) .collect() }}