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>.
pub struct LogQuery<'a> {
logs: &'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<_>>()
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: logs, } } pub fn search(&self, keyword: &str) -> Vec<&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.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, s: &str) -> Vec<&'a String> { let mut results: Vec<&'a String> = vec![]; for i in self.logs { if i.contains(s) { results.push(i); } } results }}// 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 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: logs, } } pub fn search(self, keyword: &str) -> Vec<&'a String> { let mut results = Vec::new(); for lines in self.logs { if lines.contains(keyword) { results.push(lines) } } results }}// 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 struct LogQuery<'a> { pub 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> { self.logs.iter().filter(|l| l.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.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 , key_word : &str) -> Vec<&'a String>{ self.logs.iter().filter(|log| log.contains(key_word)).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.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() }}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: &str) -> Vec<&String> { let mut matches: Vec<&String> = Vec::new(); for log in self.logs { if log.contains(keyword) { matches.push(log); } } matches }}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: &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<&String> { self.logs .into_iter() .filter(|log| log.contains(keyword)) .collect() }}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>{ if self.logs.is_empty(){ return vec![] } self.logs.iter().filter(|&log| log.contains(keyword)).collect() }}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(|line| line.contains(keyword)) .map(|line| line.as_str()) .collect() }}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<&'a String> { if self.logs.is_empty() { return vec![]; } self.logs.iter().filter(|&log| log.contains(query)).collect() }}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{ 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, search_term: &str) -> Vec<&'a String> { self.logs.iter().filter(|&x| x.contains(search_term)).collect() }}pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(s: &'a Vec<String>) -> Self { LogQuery { logs: s, } } pub fn search(&self, query: &str) -> Vec<&String> { self.logs.iter().filter(|x| x.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.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()` pub fn new(in_logs: &'a Vec<String>) -> Self { Self { logs: in_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<&'a String> { self.logs .iter() .filter(|line| line.contains(query)) .collect() }}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(&'a self, keyword: &str) -> Vec<&'a str> { self.logs .into_iter() .filter_map(|log| log.contains(keyword).then_some(log.as_str())) .collect::<Vec<&str>>() }}// 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 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().map(|s| s.as_str()).filter(|k| k.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.// 1. Finish the implementation of LogQuerypub struct LogQuery<'a> { logs: &'a [String],}impl<'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 , keyword: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect() }}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, keyword: &str) -> Vec<&'a String> { let mut r = vec![]; for log in self.logs { if log.contains(keyword) { r.push(log); } } r }}// 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.// 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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { 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() }}// 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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery{ logs: logs } } pub fn search(&self, keyword: &str) -> Vec<&String> { let log_results: Vec<_> = self.logs.iter().filter(|log| log.contains(keyword)).collect(); return log_results }}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 str> { /* let mut res: Vec<&str> = vec![]; for line in self.logs { if line.contains(keyword) { res.push(line); } } res */ self.logs.iter() .filter(|s| s.contains(keyword)) .map(|s| s.as_str()) .collect() }}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, substr: &str) -> Vec<&'a String> { let mut result = Vec::<&String>::new(); for s in self.logs { if s.contains(substr) { result.push(&s) } } result }}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() }}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, keyword: &str) -> Vec<&str> { self.logs .iter() .map(|s| s.as_str()) .filter(|l| l.contains(keyword)) .collect() }}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 String> { self.logs.iter().filter(|x| x.contains(query)).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.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: &Self, keyword: &str) -> Vec<&'a String>{ let mut output: Vec<&'a String> = Vec::new(); for log in self.logs.iter() { if log.contains(keyword) { output.push(&log); } } output }}// 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 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, str_to_search: &'a str) -> Vec<&String>{ self.logs.iter().filter(|val| val.contains(str_to_search)).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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } } pub fn search(&self, query: &str) -> Vec<&'a String> { self.logs.iter().filter(|log| { !log.is_empty() && log.contains(query) }).collect::<Vec<_>>() }}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: &'a str) -> Vec<&'a String> { self.logs .iter() .filter(|s| s.contains(keyword)) .collect() }}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, value: &str) -> Vec<&'a String> { self.logs.iter().filter(|&i| i.contains(value)).collect() }}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, query: &str) -> Vec<&String> { self.logs.iter().filter(|&x| x.contains(query)).collect() }}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, query: &str) -> Vec<&str> { self.logs .iter() .filter(|&x| x.contains(query)) .map(|x| x.as_str()) .collect() }}pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(Whatever: &'a Vec<String>) -> LogQuery<'a> { let query = LogQuery { logs: Whatever, }; query } pub fn search(&self, keyword: &str) -> Vec<&'a String> { let result = self.logs.iter().filter(|log| log.contains(keyword)); let formatted_result: Vec<_> = result.collect(); formatted_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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(logs: &Vec<String>) -> LogQuery { LogQuery { logs, } } pub fn search(&self, keyword: &str) -> Vec<&String> { let mut result = Vec::new(); for log in self.logs.iter() { if log.contains(keyword) { 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.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, pattern: &str) -> Vec<&'a String> { self.logs .iter() .filter(|log| log.contains(pattern)) .collect::<Vec<_>>() }}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: logs} } pub fn search(&self, keyword: &str) -> Vec<&'a String> { self.logs.into_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.#[derive(Debug)]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<&String> { self.logs .iter() .filter(|log_string| log_string.contains(query)) .collect() }}pub struct LogQuery<'a> { logs: &'a [String],}impl<'a> LogQuery<'a> { pub fn new(logs: &'a [String]) -> Self { Self { logs } } pub fn search(&self, keyword: &str) -> Vec<&str> { self.logs .iter().filter(|log| log.contains(keyword)).map(|s| s.as_str()).collect() }}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, keyword: &str) -> Vec<&'a String> { if self.logs.is_empty(){ return Vec::new(); } let result: Vec<&'a String> = self.logs.iter().filter(|log| log.contains(keyword)).collect(); return 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.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, keyword: &str) -> Vec<&'a String> { if self.logs.is_empty(){ return Vec::new(); } // let result: Vec<&'a String> = self.logs.iter().filter(|log| log.contains(keyword)).collect(); // 1. Initialize an empty, mutable vector to hold the results. let mut result = Vec::new(); // 2. Iterate over the original collection (using .iter() to borrow each element). for log in self.logs.iter() { // 3. Manually apply the filtering condition (log.contains(keyword)). if log.contains(keyword) { // 4. If the condition is true, push the element into the new vector. result.push(log); // Use .clone() to own the data outside the original scope if necessary } } return 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.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, keyword: &str) -> Vec<&'a String> { if self.logs.is_empty(){ return Vec::new(); } let result: Vec<&'a String> = self.logs.iter().filter(|log| log.contains(keyword)).collect(); return 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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a>{ pub fn new (logs: &'a Vec<String>)->Self{ return Self{logs}; } pub fn search(&self, query: &str)-> Vec<&'a String>{ self.logs .iter(). filter(|log| log.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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(strs: &'a Vec<String>) -> LogQuery<'a> { return Self{logs: strs} } pub fn search(self, search_string: &'a str) -> Vec<&str>{ return self.logs.iter().filter(|x| x.contains(search_string)).map(|y| y as &str).collect::<Vec<&str>>() }}// 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 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(lines: &'a Vec<String>) -> Self { LogQuery { logs: lines } }// 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(|line| line.contains(keyword)) .collect() }}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, keyword: &str) -> Vec<&String> { self.logs.iter().filter(|x| x.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.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, q: &str) -> Vec<&str> { return self.logs .iter() .filter_map(|log| { if log.contains(&q) { Some(log.as_str()) } else { None } }) .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.pub struct LogQuery<'a> { logs: &'a Vec<String>,}impl<'a> LogQuery<'a> { pub fn new(logs: &'a Vec<String>) -> LogQuery<'a> { LogQuery { logs } } pub fn search(&self, keyword: &str) -> Vec<&String> { self.logs .iter() .filter(|log| log.contains(keyword)) .collect() }}// 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.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, keyword: &str) -> Vec<&String> { self.logs.iter().filter(|l| l.contains(keyword)).collect() }}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<&'a String> { self.logs .iter() .filter(|item| item.find(query).is_some() ) .collect() }}pub struct LogQuery<'a> { pub logs: &'a Vec<String>,}// 1. Finish the implementation of LogQueryimpl<'a> LogQuery<'a> { pub fn new(arr : &'a Vec<String>) -> LogQuery<'a> { let logQuery = LogQuery{ logs : arr }; return logQuery; } pub fn search(&self,keyword:&str) -> Vec<&'a String> { let mut result: Vec<&'a String> = Vec::new(); for log in self.logs.iter() { if log.contains(keyword){ 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.