Skip to content

Commit

Permalink
chore: Replace once_cell dependency by std lib
Browse files Browse the repository at this point in the history
LazyLock is introduced in rust 1.80
  • Loading branch information
caspermeijn committed Sep 1, 2024
1 parent 96c40d7 commit 48e1442
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ authors = [
]
license = "Apache-2.0"
repository = "https://github.com/tokio-rs/prost"
rust-version = "1.71.1"
rust-version = "1.80"
edition = "2021"

[profile.bench]
Expand Down
1 change: 0 additions & 1 deletion prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ petgraph = { version = "0.6", default-features = false }
prost = { version = "0.13.2", path = "../prost", default-features = false }
prost-types = { version = "0.13.2", path = "../prost-types", default-features = false }
tempfile = "3"
once_cell = "1.17.1"
regex = { version = "1.8.1", default-features = false, features = ["std", "unicode-bool"] }

# feature: format
Expand Down
9 changes: 5 additions & 4 deletions prost-build/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use once_cell::sync::Lazy;
use prost_types::source_code_info::Location;
#[cfg(feature = "cleanup-markdown")]
use pulldown_cmark::{CodeBlockKind, Event, Options, Parser, Tag};
use regex::Regex;
use std::sync::LazyLock;

/// Comments on a Protobuf item.
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -110,9 +110,10 @@ impl Comments {
/// - escape urls as <http://foo.com>
/// - escape `[` & `]` if not already escaped and not followed by a parenthesis or bracket
fn sanitize_line(line: &str) -> String {
static RULE_URL: Lazy<Regex> = Lazy::new(|| Regex::new(r"https?://[^\s)]+").unwrap());
static RULE_BRACKETS: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(^|[^\]\\])\[(([^\]]*[^\\])?)\]([^(\[]|$)").unwrap());
static RULE_URL: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"https?://[^\s)]+").unwrap());
static RULE_BRACKETS: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(^|[^\]\\])\[(([^\]]*[^\\])?)\]([^(\[]|$)").unwrap());

let mut s = RULE_URL.replace_all(line, r"<$0>").to_string();
s = RULE_BRACKETS.replace_all(&s, r"$1\[$2\]$4").to_string();
Expand Down

0 comments on commit 48e1442

Please sign in to comment.