Skip to content

Commit

Permalink
build(deps-dev): adopt once_cell instead of lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrs committed Oct 13, 2022
1 parent a273bb2 commit 575fbeb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ uuid = { version = "1.2", features = ["v4"] }

[dev-dependencies]
pretty_env_logger = "0.4"
lazy_static = "1.4"
once_cell = "1"
rand = "0.8"
30 changes: 13 additions & 17 deletions examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;

use log::info;
use once_cell::sync::Lazy;
use poston::{Client, Settings, WorkerPool};
use pretty_env_logger;
use rand::prelude::*;
Expand All @@ -18,20 +16,18 @@ struct Human {
name: String,
}

lazy_static! {
static ref POOL: WorkerPool = {
let addr = "127.0.0.1:24224".to_string();
let settins = Settings {
flush_period: Duration::from_millis(10),
max_flush_entries: 1000,
connection_retry_timeout: Duration::from_secs(60),
write_timeout: Duration::from_secs(30),
read_timeout: Duration::from_secs(30),
..Default::default()
};
WorkerPool::with_settings(&addr, &settins).expect("Couldn't create the worker pool.")
static POOL: Lazy<WorkerPool> = Lazy::new(|| {
let addr = "127.0.0.1:24224".to_string();
let settins = Settings {
flush_period: Duration::from_millis(10),
max_flush_entries: 1000,
connection_retry_timeout: Duration::from_secs(60),
write_timeout: Duration::from_secs(30),
read_timeout: Duration::from_secs(30),
..Default::default()
};
}
WorkerPool::with_settings(&addr, &settins).expect("Couldn't create the worker pool.")
});

fn main() {
pretty_env_logger::init();
Expand Down
34 changes: 16 additions & 18 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ where
mod tests {
use super::{io, Duration, ToSocketAddrs};
use super::{Connect, ConnectionSettings, Reconnect, Stream};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::collections::VecDeque;
use std::convert::From;
use std::io::{Read, Write};
Expand Down Expand Up @@ -379,23 +379,21 @@ mod tests {

#[derive(Debug)]
struct TS;
lazy_static! {
static ref QUEUE: Mutex<RefCell<VecDeque<Result<usize, io::Error>>>> = {
let mut q = VecDeque::new();

let scenario = vec![
Err(io::Error::from(io::ErrorKind::TimedOut)), // write ng.
Err(io::Error::from(io::ErrorKind::BrokenPipe)), // write ng.
Ok(1), // write ok.
Err(io::Error::from(io::ErrorKind::WouldBlock)), // read ng.
Ok(55), // read ok.
];
for s in scenario {
q.push_back(s);
}
Mutex::new(RefCell::new(q))
};
};
static QUEUE: Lazy<Mutex<RefCell<VecDeque<Result<usize, io::Error>>>>> = Lazy::new(|| {
let mut q = VecDeque::new();

let scenario = vec![
Err(io::Error::from(io::ErrorKind::TimedOut)), // write ng.
Err(io::Error::from(io::ErrorKind::BrokenPipe)), // write ng.
Ok(1), // write ok.
Err(io::Error::from(io::ErrorKind::WouldBlock)), // read ng.
Ok(55), // read ok.
];
for s in scenario {
q.push_back(s);
}
Mutex::new(RefCell::new(q))
});

impl Connect<TS> for TS {
fn connect<A>(_addr: A, _s: ConnectionSettings) -> io::Result<TS>
Expand Down

0 comments on commit 575fbeb

Please sign in to comment.