diff --git a/Cargo.lock b/Cargo.lock index c6696c606..2e3f383bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5235,10 +5235,10 @@ dependencies = [ name = "uv-normalize" version = "0.0.1" dependencies = [ - "arcstr", "rkyv", "schemars", "serde", + "uv-small-str", ] [[package]] @@ -5622,6 +5622,16 @@ dependencies = [ "winreg", ] +[[package]] +name = "uv-small-str" +version = "0.0.1" +dependencies = [ + "arcstr", + "rkyv", + "schemars", + "serde", +] + [[package]] name = "uv-state" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index e97d1ae66..ad3717a20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,10 +59,11 @@ uv-resolver = { path = "crates/uv-resolver" } uv-scripts = { path = "crates/uv-scripts" } uv-settings = { path = "crates/uv-settings" } uv-shell = { path = "crates/uv-shell" } +uv-small-str = { path = "crates/uv-small-str" } uv-state = { path = "crates/uv-state" } uv-static = { path = "crates/uv-static" } -uv-trampoline-builder = { path = "crates/uv-trampoline-builder" } uv-tool = { path = "crates/uv-tool" } +uv-trampoline-builder = { path = "crates/uv-trampoline-builder" } uv-types = { path = "crates/uv-types" } uv-version = { path = "crates/uv-version" } uv-virtualenv = { path = "crates/uv-virtualenv" } diff --git a/crates/uv-normalize/Cargo.toml b/crates/uv-normalize/Cargo.toml index 8d9c1c23e..d40faf3d7 100644 --- a/crates/uv-normalize/Cargo.toml +++ b/crates/uv-normalize/Cargo.toml @@ -11,7 +11,11 @@ doctest = false workspace = true [dependencies] -arcstr = { workspace = true } +uv-small-str = { workspace = true } + rkyv = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } + +[features] +schemars = ["dep:schemars", "uv-small-str/schemars"] diff --git a/crates/uv-normalize/src/extra_name.rs b/crates/uv-normalize/src/extra_name.rs index bc3c5f737..11a6707ef 100644 --- a/crates/uv-normalize/src/extra_name.rs +++ b/crates/uv-normalize/src/extra_name.rs @@ -4,7 +4,8 @@ use std::str::FromStr; use serde::{Deserialize, Deserializer, Serialize}; -use crate::small_string::SmallString; +use uv_small_str::SmallString; + use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError}; /// The normalized name of an extra dependency. diff --git a/crates/uv-normalize/src/group_name.rs b/crates/uv-normalize/src/group_name.rs index a3ecb74c8..a11ed01bb 100644 --- a/crates/uv-normalize/src/group_name.rs +++ b/crates/uv-normalize/src/group_name.rs @@ -5,7 +5,8 @@ use std::sync::LazyLock; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use crate::small_string::SmallString; +use uv_small_str::SmallString; + use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError}; /// The normalized name of a dependency group. diff --git a/crates/uv-normalize/src/lib.rs b/crates/uv-normalize/src/lib.rs index 17beee6b9..06234db96 100644 --- a/crates/uv-normalize/src/lib.rs +++ b/crates/uv-normalize/src/lib.rs @@ -5,13 +5,13 @@ pub use dist_info_name::DistInfoName; pub use extra_name::ExtraName; pub use group_name::{GroupName, DEV_DEPENDENCIES}; pub use package_name::PackageName; -use small_string::SmallString; + +use uv_small_str::SmallString; mod dist_info_name; mod extra_name; mod group_name; mod package_name; -mod small_string; /// Validate and normalize an owned package or extra name. pub(crate) fn validate_and_normalize_owned(name: String) -> Result { diff --git a/crates/uv-normalize/src/package_name.rs b/crates/uv-normalize/src/package_name.rs index 742867e7f..59d7ea912 100644 --- a/crates/uv-normalize/src/package_name.rs +++ b/crates/uv-normalize/src/package_name.rs @@ -4,7 +4,8 @@ use std::str::FromStr; use serde::{Deserialize, Deserializer, Serialize}; -use crate::small_string::SmallString; +use uv_small_str::SmallString; + use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError}; /// The normalized name of a package. diff --git a/crates/uv-small-str/Cargo.toml b/crates/uv-small-str/Cargo.toml new file mode 100644 index 000000000..c8e6cf18b --- /dev/null +++ b/crates/uv-small-str/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "uv-small-str" +version = "0.0.1" +edition = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +documentation = { workspace = true } +repository = { workspace = true } +authors = { workspace = true } +license = { workspace = true } + +[lib] +doctest = false + +[lints] +workspace = true + +[dependencies] +arcstr = { workspace = true } +rkyv = { workspace = true } +schemars = { workspace = true, optional = true } +serde = { workspace = true } diff --git a/crates/uv-normalize/src/small_string.rs b/crates/uv-small-str/src/lib.rs similarity index 86% rename from crates/uv-normalize/src/small_string.rs rename to crates/uv-small-str/src/lib.rs index ca6d3ea6d..20d66190e 100644 --- a/crates/uv-normalize/src/small_string.rs +++ b/crates/uv-small-str/src/lib.rs @@ -1,11 +1,16 @@ use std::cmp::PartialEq; use std::ops::Deref; -/// An optimized small string type for short identifiers, like package names. -/// -/// Represented as an [`arcstr::ArcStr`] internally. -#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub(crate) struct SmallString(arcstr::ArcStr); +/// An optimized type for immutable identifiers. Represented as an [`arcstr::ArcStr`] internally. +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct SmallString(arcstr::ArcStr); + +impl From for SmallString { + #[inline] + fn from(s: arcstr::ArcStr) -> Self { + Self(s) + } +} impl From<&str> for SmallString { #[inline] @@ -28,6 +33,13 @@ impl AsRef for SmallString { } } +impl core::borrow::Borrow for SmallString { + #[inline] + fn borrow(&self) -> &str { + self + } +} + impl Deref for SmallString { type Target = str;