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<_>>()
recursivemaze
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 str> { self.logs.iter().filter(|i| i.contains(keyword)).map(|s| s as &str).collect() }}
PowVT
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 str> { self.logs.iter().filter(|i| i.contains(keyword)).map(|s| s as &str).collect() }}
SirVer
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 str> { self.logs.iter().filter(|i| i.contains(keyword)).map(|s| s 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.
mrsalo
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(|x| x.contains(keyword)) .collect() }}
theandi667
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, needle: &str) -> Vec<&str> { self.logs.iter().filter(|log| log.contains(&needle)).map(String::as_str).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.
SchnobiTobi
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 } } pub fn search(&self,s: &str)-> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(s)).collect() }}// 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.
LenRemmerswaal
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, needle: &str ) -> Vec<&'a str> { self.logs.iter().filter(|s| s.contains(needle)).map(|s| s.as_str()).collect() }}
rynfixme
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() }}// 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.
kadachi2
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, keyword: &str) -> Vec<&'a String> { self.logs.iter() .filter(|log| { log.contains(keyword) }) .collect() }}
Muhammad-Dennis
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, log: &'a str) -> Vec<&'a String> { // Procedural approach // let mut logs = vec![]; // for line in self.logs { // if line.contains(&log) { // logs.push(line) // } // } // logs // Functional approach self.logs.iter().filter(|line| line.contains(log)).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.
alexfict
pub struct LogQuery<'a> { pub logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl <'a> LogQuery<'a> { pub fn new (str: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs: str } } pub fn search(&self, search_str: &str) -> Vec<&String> { let mut out = Vec::new(); for log in self.logs.iter() { match log.find(search_str) { Some(index) => { println!("found on index {}", index); out.push(log); }, None => println!("search string not found") } } out }}
daves003
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>) -> LogQuery<'a> { LogQuery{ 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, keyword: &str) -> Vec<&String> { self.logs.iter().filter(|s| s.contains(keyword)).collect() }}
MShadiF
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//impl <'a>LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { LogQuery { logs } } pub fn search(&self, keyword: &'a str) -> Vec<&'a String> { return self.logs.iter().filter(|log| log.contains(keyword)).collect(); }}// 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.
kill-your-soul
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: logs } } pub fn search(&self, token: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(token)).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.
Bodomit
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: 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, token: &str) -> Vec<&String> { self.logs.iter().filter(|log| log.contains(token)).collect::<Vec<&String>>() }}
MarcelBlanck-Philips
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: &'a str) -> Vec<&'a String> { self.logs.iter().filter(|s| s.contains(keyword)).collect() }}
andreabergia
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 { return Self { logs } } pub fn search(&self, log: &str) -> Vec<&'a String> { self.logs.iter() .filter(|s| s.contains(log)) .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.
WuHan0608
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> { self.logs.iter() .filter(|s| s.contains(keyword)) .collect::<Vec<&String>>() }}
filippodebortoli
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 } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| log.contains(keyword)).collect::<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.
j-toscani
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 { return LogQuery { logs } } pub fn search(self, needle: &str) -> Vec<&'a String> { return self.logs.iter().filter(|log| log.contains(needle)).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.
dchenbecker
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|line| line.contains(keyword)).collect() }}
Laifsyn
pub struct LogQuery<'a> { logs: &'a [String],}impl<'a> LogQuery<'a> { // When Ref-ing Vec<T>s, it is usually better to straight up use &[T] unless proven otherwise pub fn new(logs: &'a [String]) -> LogQuery<'a> { LogQuery { logs } } pub fn search(&self, slice: &str) -> Vec<&str> { self.logs.iter().filter(|s| s.contains(slice)).map(String::as_str).collect() }}
Pathal
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 } } pub fn search(&self, pattern: &str) -> Vec<&str> { self.logs.iter() .filter(|s| s.contains(pattern)) .map(|s| s.as_ref()) .collect() }}
andrey-yu
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(l: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs: l } } pub fn search(self: LogQuery<'a>, keyword: &'a str) -> Vec<&String> { self.logs.iter() .filter(|&s| s.contains(keyword)) .collect() }}
dpathakj
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> { self.logs.iter() .filter(|s| s.contains(keyword)) .map(|s| s.as_ref()) .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.
insky7
pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(x: &'a Vec<String>) -> Self { Self { logs: x } } pub fn search(self, keyword: &str) -> Vec<&'a String> { let x = self .logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<_>>(); x }}
maxnavarrollaven
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { // Associated function to create a new LogQuery pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } } // Method to search for a keyword in the logs and return matching entries pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<&'a String>>() }}fn main() { // Example usage let logs: Vec<String> = vec![ String::from("Toy Tracker 3000: All systems operational."), String::from("SleighOS: Reboot required."), String::from("Reindeer AI: Blitzen is leading the way."), String::from("SleighOS: Blitzen override detected."), ]; let log_query = LogQuery::new(&logs); let keyword = "Blitzen"; let results = log_query.search(keyword); for log in results { println!("{}", log); }}
bindermuehle
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 } } pub fn search(self, value: &str) -> Vec<&'a String> { self.logs.iter().filter(|w| w.contains(value)).collect() }}
gtowers-dukosi
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> Self { Self{logs: logs} } pub fn search(self, keyword: &'a str) -> Vec<&str> { let mut found: Vec<&str> = Vec::new(); for i in self.logs { if i.contains(keyword) { found.push(&i); } } found }}
Kada-quantum
pub struct LogQuery<'a> { logs: &'a [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 [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, f: &str) -> Vec<&String> { self.logs.iter().filter(|s| s.contains(f)).collect()}}
anxolerd
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 { return 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> { self.logs.iter().filter(|s| s.contains(keyword)).collect::<Vec<&String>>() }}
rgreinho
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<&String> { self.logs.iter().filter(|s| s.contains(keyword)).collect::<Vec<&String>>() }}
shafer-hess
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(|log| log.contains(keyword)) .collect::<Vec<&'a String>>() }}
shafer-hess
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 str>{ let mut v: Vec<&'a str> = Vec::new(); for log in self.logs { if log.contains(keyword) { v.push(log); } } v }}
mathieu-lemay
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 { return Self { logs }; } pub fn search(&self, p: &str) -> Vec<&'a String> { self.logs.iter().filter(|l| l.contains(p)).collect::<Vec<&'a String>>() }}
cremno
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> { self.logs.iter().filter(|e| e.contains(keyword)).collect() }}
rostyq
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(&'a self, keyword: &'_ str) -> Vec<&'a str> { self.logs.iter().map(String::as_str).filter(|log| log.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.
edgarcnp
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, query: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(query)) .collect() }}
Brack0
pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery { LogQuery { logs } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect() }}
MSalah73
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 } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.iter().filter(|&i| i.contains(&keyword.to_string())).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.
MSalah73
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 } } pub fn search(&self, keyword: &str) -> Vec<&'a String> { if self.logs.is_empty(){ return vec![]; } if keyword.is_empty() { return self.logs.iter().map(|i| i).collect(); } self.logs.iter().filter(|&i| i.contains(&keyword.to_string())).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.
dav-rei
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<_>>() }}
overplumbum
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: 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<&String> { self.logs.iter().filter(|log| log.contains(slice)).collect() }}
CianciuStyles
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() }}
tarpaha
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<&String> { let mut result = vec![]; for string in self.logs { if string.contains(keyword) { result.push(string); } } result }}// 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
lazyfuhrer
pub struct LogQuery<'a> { pub logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(vec_of_strings: &'a Vec<String>) -> LogQuery<'a> { LogQuery{logs: vec_of_strings} } pub fn search(&self, string_slice: &str) -> Vec<&'a String> { self.logs.iter() .filter(|log| log.contains(string_slice)) .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.
jsulmont
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 } } // 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> { self.logs .iter() .filter(|log| log.contains(query)) .map(|log| log.as_str()) .collect() }}
CyberMuz
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, query: &str) -> Vec<&str> { let mut result: Vec<&str> = Vec::new(); for log in self.logs { if log.contains(query) { result.push(log); } } result }}
hillonyechekwa
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>{ let result = self.logs .iter() .filter(|log| log.contains(keyword)) .collect::<Vec<_>>(); return result }}
sander-b-postnl
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> { let mut result = Vec::new(); for log in self.logs { if log.contains(query) { result.push(log); } } result }}// 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.