add constant-expression string utils
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
084751ae38
commit
b3f2288d07
10 changed files with 47 additions and 0 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -589,6 +589,7 @@ dependencies = [
|
||||||
"conduit_router",
|
"conduit_router",
|
||||||
"conduit_service",
|
"conduit_service",
|
||||||
"console-subscriber",
|
"console-subscriber",
|
||||||
|
"const-str",
|
||||||
"hardened_malloc-rs",
|
"hardened_malloc-rs",
|
||||||
"log",
|
"log",
|
||||||
"opentelemetry",
|
"opentelemetry",
|
||||||
|
@ -613,6 +614,7 @@ dependencies = [
|
||||||
"conduit_api",
|
"conduit_api",
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
"conduit_service",
|
"conduit_service",
|
||||||
|
"const-str",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"ruma",
|
"ruma",
|
||||||
|
@ -635,6 +637,7 @@ dependencies = [
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
"conduit_database",
|
"conduit_database",
|
||||||
"conduit_service",
|
"conduit_service",
|
||||||
|
"const-str",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hmac",
|
"hmac",
|
||||||
"http 1.1.0",
|
"http 1.1.0",
|
||||||
|
@ -665,6 +668,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"checked_ops",
|
"checked_ops",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"const-str",
|
||||||
"either",
|
"either",
|
||||||
"figment",
|
"figment",
|
||||||
"hardened_malloc-rs",
|
"hardened_malloc-rs",
|
||||||
|
@ -701,6 +705,7 @@ name = "conduit_database"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
|
"const-str",
|
||||||
"log",
|
"log",
|
||||||
"rust-rocksdb-uwu",
|
"rust-rocksdb-uwu",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -720,6 +725,7 @@ dependencies = [
|
||||||
"conduit_api",
|
"conduit_api",
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
"conduit_service",
|
"conduit_service",
|
||||||
|
"const-str",
|
||||||
"http 1.1.0",
|
"http 1.1.0",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper 1.4.1",
|
"hyper 1.4.1",
|
||||||
|
@ -746,6 +752,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"conduit_core",
|
"conduit_core",
|
||||||
"conduit_database",
|
"conduit_database",
|
||||||
|
"const-str",
|
||||||
"cyborgtime",
|
"cyborgtime",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hickory-resolver",
|
"hickory-resolver",
|
||||||
|
@ -817,6 +824,12 @@ version = "0.9.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const-str"
|
||||||
|
version = "0.5.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3618cccc083bb987a415d85c02ca6c9994ea5b44731ec28b9ecf09658655fba9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "const_panic"
|
name = "const_panic"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
|
|
|
@ -25,6 +25,9 @@ version = "0.4.5"
|
||||||
[workspace.metadata.crane]
|
[workspace.metadata.crane]
|
||||||
name = "conduit"
|
name = "conduit"
|
||||||
|
|
||||||
|
[workspace.dependencies.const-str]
|
||||||
|
version = "0.5.7"
|
||||||
|
|
||||||
[workspace.dependencies.sanitize-filename]
|
[workspace.dependencies.sanitize-filename]
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ clap.workspace = true
|
||||||
conduit-api.workspace = true
|
conduit-api.workspace = true
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
conduit-service.workspace = true
|
conduit-service.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
ruma.workspace = true
|
ruma.workspace = true
|
||||||
|
|
|
@ -41,6 +41,7 @@ bytes.workspace = true
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
conduit-database.workspace = true
|
conduit-database.workspace = true
|
||||||
conduit-service.workspace = true
|
conduit-service.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
hmac.workspace = true
|
hmac.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
|
|
|
@ -55,6 +55,7 @@ axum.workspace = true
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
checked_ops.workspace = true
|
checked_ops.workspace = true
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
either.workspace = true
|
either.workspace = true
|
||||||
figment.workspace = true
|
figment.workspace = true
|
||||||
http-body-util.workspace = true
|
http-body-util.workspace = true
|
||||||
|
|
|
@ -2,6 +2,30 @@ use crate::Result;
|
||||||
|
|
||||||
pub const EMPTY: &str = "";
|
pub const EMPTY: &str = "";
|
||||||
|
|
||||||
|
/// Constant expression to bypass format! if the argument is a string literal
|
||||||
|
/// but not a format string. If the literal is a format string then String is
|
||||||
|
/// returned otherwise the input (i.e. &'static str) is returned. If multiple
|
||||||
|
/// arguments are provided the first is assumed to be a format string.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! format_maybe {
|
||||||
|
($s:literal) => {
|
||||||
|
if $crate::is_format!($s) { std::format!($s).into() } else { $s.into() }
|
||||||
|
};
|
||||||
|
|
||||||
|
($($args:expr),*) => {
|
||||||
|
std::format!($($args),*).into()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constant expression to decide if a literal is a format string. Note: could
|
||||||
|
/// use some improvement.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! is_format {
|
||||||
|
($s:literal) => {
|
||||||
|
::const_str::contains!($s, "{") && ::const_str::contains!($s, "}")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Find the common prefix from a collection of strings and return a slice
|
/// Find the common prefix from a collection of strings and return a slice
|
||||||
/// ```
|
/// ```
|
||||||
/// use conduit_core::utils::string::common_prefix;
|
/// use conduit_core::utils::string::common_prefix;
|
||||||
|
|
|
@ -36,6 +36,7 @@ zstd_compression = [
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
rust-rocksdb.workspace = true
|
rust-rocksdb.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
|
|
|
@ -147,6 +147,7 @@ log.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
|
|
||||||
opentelemetry.workspace = true
|
opentelemetry.workspace = true
|
||||||
opentelemetry.optional = true
|
opentelemetry.optional = true
|
||||||
|
|
|
@ -55,6 +55,7 @@ conduit-admin.workspace = true
|
||||||
conduit-api.workspace = true
|
conduit-api.workspace = true
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
conduit-service.workspace = true
|
conduit-service.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tower.workspace = true
|
tower.workspace = true
|
||||||
|
|
|
@ -42,6 +42,7 @@ base64.workspace = true
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
conduit-core.workspace = true
|
conduit-core.workspace = true
|
||||||
conduit-database.workspace = true
|
conduit-database.workspace = true
|
||||||
|
const-str.workspace = true
|
||||||
cyborgtime.workspace = true
|
cyborgtime.workspace = true
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
hickory-resolver.workspace = true
|
hickory-resolver.workspace = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue