mod front_of_house;
pub mod persist;
use persist::redis_operation;
mod aa;
use std::collections::HashMap;
use std::fmt::Result;
use std::io::Result as IoResult;
use crate::front_of_house::hosting;
pub use crate::front_of_house::hosting as hos;
use std::{cmp::Ordering, fs, io};
use std::collections::*;
use std::error::Error;
pub fn add_one(x: i32) -> i32 {
x + 1
}
pub fn eat_at_restaurant() {
crate::front_of_house::hosting::add_to_waitlist();
front_of_house::hosting::add_to_waitlist();
hosting::add_to_waitlist();
hos::add_to_waitlist();
let mut map = HashMap::new();
map.insert(1, 2);
}
pub fn save() {
redis_operation::redis_save("a", "b");
persist::save();
}
pub fn run(config: &Config) -> std::result::Result<(), Box<dyn Error>> {
match fs::read_to_string(&config.filename) {
Ok(content) => {
println!("Content loaded:{:?}", content);
search(&config.query, &content);
}
Err(e) => {
panic!("{},file not exists!", config.filename);
}
}
Ok(())
}
pub fn search(query: &str, content: &str) -> Option<String> {
for line in content.lines() {
if line.contains(query) {
println!("找到:{}", line);
return Some(line.to_string());
}
}
None
}
pub struct Config {
query: String,
filename: String,
}
impl Config {
pub fn new(args: &[String]) -> std::result::Result<Config, &'static str> {
;
let query = args[1].clone();
if query.len() < 3 {
return Err("query less than 3");
}
let filename = args[2].clone();
Ok(Config { query, filename })
}
}