commit 7588b23fcb2208b76da4b19a65a5438a2851e113
parent 8e137140111d384f23d72ffbea3df50a9792a0e5
Author: Matt Brubeck <mbrubeck@limpet.net>
Date: Fri, 22 May 2020 19:00:21 -0700
Switch from lazy_static to once_cell
Diffstat:
3 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -6,7 +6,7 @@ version = "1.1.0"
dependencies = [
"async-std",
"async-tls",
- "lazy_static",
+ "once_cell",
"rustls",
"tree_magic",
"url",
diff --git a/Cargo.toml b/Cargo.toml
@@ -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"
diff --git a/src/main.rs b/src/main.rs
@@ -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) => {