mirror of https://github.com/astral-sh/uv
Add a shared `uv-small-str` crate (#10545)
## Summary I want to use `SmallString` elsewhere.
This commit is contained in:
parent
4ca5e048cc
commit
1e48c12837
|
|
@ -5235,10 +5235,10 @@ dependencies = [
|
||||||
name = "uv-normalize"
|
name = "uv-normalize"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arcstr",
|
|
||||||
"rkyv",
|
"rkyv",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
|
"uv-small-str",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -5622,6 +5622,16 @@ dependencies = [
|
||||||
"winreg",
|
"winreg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uv-small-str"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"arcstr",
|
||||||
|
"rkyv",
|
||||||
|
"schemars",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uv-state"
|
name = "uv-state"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,11 @@ uv-resolver = { path = "crates/uv-resolver" }
|
||||||
uv-scripts = { path = "crates/uv-scripts" }
|
uv-scripts = { path = "crates/uv-scripts" }
|
||||||
uv-settings = { path = "crates/uv-settings" }
|
uv-settings = { path = "crates/uv-settings" }
|
||||||
uv-shell = { path = "crates/uv-shell" }
|
uv-shell = { path = "crates/uv-shell" }
|
||||||
|
uv-small-str = { path = "crates/uv-small-str" }
|
||||||
uv-state = { path = "crates/uv-state" }
|
uv-state = { path = "crates/uv-state" }
|
||||||
uv-static = { path = "crates/uv-static" }
|
uv-static = { path = "crates/uv-static" }
|
||||||
uv-trampoline-builder = { path = "crates/uv-trampoline-builder" }
|
|
||||||
uv-tool = { path = "crates/uv-tool" }
|
uv-tool = { path = "crates/uv-tool" }
|
||||||
|
uv-trampoline-builder = { path = "crates/uv-trampoline-builder" }
|
||||||
uv-types = { path = "crates/uv-types" }
|
uv-types = { path = "crates/uv-types" }
|
||||||
uv-version = { path = "crates/uv-version" }
|
uv-version = { path = "crates/uv-version" }
|
||||||
uv-virtualenv = { path = "crates/uv-virtualenv" }
|
uv-virtualenv = { path = "crates/uv-virtualenv" }
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@ doctest = false
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arcstr = { workspace = true }
|
uv-small-str = { workspace = true }
|
||||||
|
|
||||||
rkyv = { workspace = true }
|
rkyv = { workspace = true }
|
||||||
schemars = { workspace = true, optional = true }
|
schemars = { workspace = true, optional = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
schemars = ["dep:schemars", "uv-small-str/schemars"]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
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};
|
use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError};
|
||||||
|
|
||||||
/// The normalized name of an extra dependency.
|
/// The normalized name of an extra dependency.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ use std::sync::LazyLock;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
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};
|
use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError};
|
||||||
|
|
||||||
/// The normalized name of a dependency group.
|
/// The normalized name of a dependency group.
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ pub use dist_info_name::DistInfoName;
|
||||||
pub use extra_name::ExtraName;
|
pub use extra_name::ExtraName;
|
||||||
pub use group_name::{GroupName, DEV_DEPENDENCIES};
|
pub use group_name::{GroupName, DEV_DEPENDENCIES};
|
||||||
pub use package_name::PackageName;
|
pub use package_name::PackageName;
|
||||||
use small_string::SmallString;
|
|
||||||
|
use uv_small_str::SmallString;
|
||||||
|
|
||||||
mod dist_info_name;
|
mod dist_info_name;
|
||||||
mod extra_name;
|
mod extra_name;
|
||||||
mod group_name;
|
mod group_name;
|
||||||
mod package_name;
|
mod package_name;
|
||||||
mod small_string;
|
|
||||||
|
|
||||||
/// Validate and normalize an owned package or extra name.
|
/// Validate and normalize an owned package or extra name.
|
||||||
pub(crate) fn validate_and_normalize_owned(name: String) -> Result<SmallString, InvalidNameError> {
|
pub(crate) fn validate_and_normalize_owned(name: String) -> Result<SmallString, InvalidNameError> {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
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};
|
use crate::{validate_and_normalize_owned, validate_and_normalize_ref, InvalidNameError};
|
||||||
|
|
||||||
/// The normalized name of a package.
|
/// The normalized name of a package.
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
use std::cmp::PartialEq;
|
use std::cmp::PartialEq;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// An optimized small string type for short identifiers, like package names.
|
/// An optimized type for immutable identifiers. Represented as an [`arcstr::ArcStr`] internally.
|
||||||
///
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
/// Represented as an [`arcstr::ArcStr`] internally.
|
pub struct SmallString(arcstr::ArcStr);
|
||||||
#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub(crate) struct SmallString(arcstr::ArcStr);
|
impl From<arcstr::ArcStr> for SmallString {
|
||||||
|
#[inline]
|
||||||
|
fn from(s: arcstr::ArcStr) -> Self {
|
||||||
|
Self(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&str> for SmallString {
|
impl From<&str> for SmallString {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -28,6 +33,13 @@ impl AsRef<str> for SmallString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::borrow::Borrow<str> for SmallString {
|
||||||
|
#[inline]
|
||||||
|
fn borrow(&self) -> &str {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for SmallString {
|
impl Deref for SmallString {
|
||||||
type Target = str;
|
type Target = str;
|
||||||
|
|
||||||
Loading…
Reference in New Issue