Skip to content

Commit 1d488ed

Browse files
committed
obey clippy
1 parent 4bb5854 commit 1d488ed

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/config.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::Deserialize;
2+
use std::error::Error;
23
use std::path::PathBuf;
34
use std::{collections::HashMap, fs};
45

@@ -31,23 +32,23 @@ fn parsehosts(config: ConfigToml) -> HashMap<String, String> {
3132
for host in config.host {
3233
for from in host.from {
3334
let to = &host.to;
34-
hosts.insert(from.to_string(), to.to_string());
35+
hosts.insert(from, to.to_string());
3536
}
3637
}
3738
hosts
3839
}
3940

4041
// main function to get config struct
41-
pub fn parse(file: PathBuf) -> Config {
42+
pub fn parse(file: PathBuf) -> Result<Config, Box<dyn Error>> {
4243
// load config
43-
let buf = fs::read_to_string(file).unwrap();
44+
let buf = fs::read_to_string(file)?;
4445

4546
// parse file contents
46-
let config: ConfigToml = toml::from_str(&buf).unwrap();
47+
let config: ConfigToml = toml::from_str(&buf)?;
4748

48-
// create main config struct
49-
Config {
49+
// create and return main config struct
50+
Ok(Config {
5051
port: config.port,
5152
hosts: parsehosts(config),
52-
}
53+
})
5354
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ mod server;
77
#[tokio::main]
88
async fn main() -> Result<(), Box<dyn Error>> {
99
// logging setup
10-
simple_logger::init_with_level(log::Level::Info).unwrap();
10+
simple_logger::init_with_level(log::Level::Info)?;
1111

1212
// get args
1313
let opts = args::parse();
1414

1515
// get config
16-
let config = config::parse(opts.path);
16+
let config = config::parse(opts.path)?;
1717

1818
// server setup
1919
let server = server::Server {

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async fn handle(inbound: TcpStream, hosts: HashMap<String, String>) -> Result<()
5151
// parse headers
5252
let p = headers.iter().position(|&h| h.name == "Host").unwrap();
5353
let host = String::from_utf8_lossy(headers[p].value).to_string();
54-
let to = hosts.get(&host).unwrap();
54+
let to = &hosts[&host];
5555

5656
// proxy
5757
let proxy = proxy(inbound, to.to_string()).map(|r| {

0 commit comments

Comments
 (0)