Switch from lazy_static to once_cell

This commit is contained in:
Matt Brubeck 2020-05-22 19:00:21 -07:00
parent 8e13714011
commit 7588b23fcb
3 changed files with 8 additions and 10 deletions

2
Cargo.lock generated
View file

@ -6,7 +6,7 @@ version = "1.1.0"
dependencies = [
"async-std",
"async-tls",
"lazy_static",
"once_cell",
"rustls",
"tree_magic",
"url",

View file

@ -13,7 +13,7 @@ edition = "2018"
[dependencies]
async-tls = "0.7.0"
async-std = "1.5"
lazy_static = "1.4"
once_cell = "1.4"
rustls = "0.17.0"
tree_magic = "0.2.3"
url = "2.1"

View file

@ -7,7 +7,7 @@ use {
task,
},
async_tls::TlsAcceptor,
lazy_static::lazy_static,
once_cell::sync::Lazy,
std::{error::Error, ffi::OsStr, marker::Unpin, str, sync::Arc},
url::Url,
};
@ -36,12 +36,6 @@ fn main() -> Result {
})
}
lazy_static! {
static ref ARGS: Args = args()
.expect("usage: agate <addr:port> <dir> <cert> <key>");
static ref ACCEPTOR: TlsAcceptor = acceptor().unwrap();
}
fn args() -> Option<Args> {
let mut args = std::env::args().skip(1);
Some(Args {
@ -52,6 +46,9 @@ fn args() -> Option<Args> {
})
}
static ARGS: Lazy<Args> =
Lazy::new(|| args().expect("usage: agate <addr:port> <dir> <cert> <key>"));
fn acceptor() -> Result<TlsAcceptor> {
use rustls::{ServerConfig, NoClientAuth, internal::pemfile::{certs, pkcs8_private_keys}};
use std::{io::BufReader, fs::File};
@ -69,7 +66,8 @@ fn acceptor() -> Result<TlsAcceptor> {
/// Handle a single client session (request + response).
async fn connection(stream: TcpStream) -> Result {
use async_std::io::prelude::*;
static ACCEPTOR: Lazy<TlsAcceptor> = Lazy::new(|| acceptor().unwrap());
let mut stream = ACCEPTOR.accept(stream).await?;
match parse_request(&mut stream).await {
Ok(url) => {