Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch lazy_static to once_cell #169

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dashmap = "3.11"
crossbeam = "0.7"
uuid = { version = "0.8", features = ["v4"] }
regex = "1"
lazy_static = "1"
once_cell = "1"
log = "0.4"
asynchronous-codec = "0.6"
async-std = { version = "1", features = ["attributes"], optional = true }
Expand Down
35 changes: 16 additions & 19 deletions src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod transport;
pub use host::Host;
pub use transport::Transport;

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use std::fmt;
use std::net::SocketAddr;
Expand All @@ -16,6 +16,9 @@ pub use error::EndpointError;

pub type Port = u16;

static TRANSPORT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^([[:lower:]]+)://(.+)$").unwrap());
static HOST_PORT_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(.+):(\d+)$").unwrap());

/// Represents a ZMQ Endpoint.
///
/// # Examples
Expand Down Expand Up @@ -58,11 +61,6 @@ impl FromStr for Endpoint {
type Err = EndpointError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
lazy_static! {
static ref TRANSPORT_REGEX: Regex = Regex::new(r"^([[:lower:]]+)://(.+)$").unwrap();
static ref HOST_PORT_REGEX: Regex = Regex::new(r"^(.+):(\d+)$").unwrap();
}

let caps = TRANSPORT_REGEX
.captures(s)
.ok_or(EndpointError::Syntax("Could not parse transport"))?;
Expand Down Expand Up @@ -149,21 +147,20 @@ mod private {
#[cfg(test)]
mod tests {
use super::*;
use lazy_static::lazy_static;

lazy_static! {
static ref PAIRS: Vec<(Endpoint, &'static str)> = vec![
static PAIRS: Lazy<Vec<(Endpoint, &'static str)>> = Lazy::new(|| {
vec![
(
Endpoint::Ipc(Some(PathBuf::from("/tmp/asdf"))),
"ipc:///tmp/asdf"
"ipc:///tmp/asdf",
),
(
Endpoint::Ipc(Some(PathBuf::from("my/dir_1/dir-2"))),
"ipc://my/dir_1/dir-2"
"ipc://my/dir_1/dir-2",
),
(
Endpoint::Ipc(Some(PathBuf::from("@abstract/namespace"))),
"ipc://@abstract/namespace"
"ipc://@abstract/namespace",
),
(
Endpoint::Tcp(Host::Domain("www.example.com".to_string()), 1234),
Expand All @@ -183,22 +180,22 @@ mod tests {
),
(
Endpoint::Tcp(Host::Domain("i❤.ws".to_string()), 80),
"tcp://i❤.ws:80"
"tcp://i❤.ws:80",
),
(
Endpoint::Tcp(Host::Domain("xn--i-7iq.ws".to_string()), 80),
"tcp://xn--i-7iq.ws:80"
"tcp://xn--i-7iq.ws:80",
),
(
Endpoint::Tcp(Host::Ipv4("127.0.0.1".parse().unwrap()), 65535),
"tcp://127.0.0.1:65535"
"tcp://127.0.0.1:65535",
),
(
Endpoint::Tcp(Host::Ipv4("127.0.0.1".parse().unwrap()), 0),
"tcp://127.0.0.1:0"
)
];
}
"tcp://127.0.0.1:0",
),
]
});

#[test]
fn test_endpoint_display() {
Expand Down