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"
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -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" }
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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<SmallString, InvalidNameError> {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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::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<arcstr::ArcStr> for SmallString {
|
||||
#[inline]
|
||||
fn from(s: arcstr::ArcStr) -> Self {
|
||||
Self(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for SmallString {
|
||||
#[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 {
|
||||
type Target = str;
|
||||
|
||||
Loading…
Reference in New Issue