Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ uuid = { version = "1.10", features = ["v1", "v3", "v4", "v5", "v6", "v7"] }
serde = { version = "1.0", features = ["derive"] }
tracing = { version = "0.1" }
arbitrary = { version = "1.3.2", features = ["derive"] }
smol_str = { version = "0.3.6" }

# Dev dependencies
proptest = { version = "1.5.0", features = ["proptest-macro"] }
Expand Down
1 change: 1 addition & 0 deletions crates/mti/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["data-structures", "development-tools", "encoding", "parser-implem
[dependencies]
typeid_prefix = { workspace = true }
typeid_suffix = { workspace = true }
smol_str = { workspace = true }
serde = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }

Expand Down
13 changes: 7 additions & 6 deletions crates/mti/src/magic_type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt::{Display, Formatter};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::str::FromStr;
use smol_str::{SmolStr, ToSmolStr, format_smolstr};
use typeid_prefix::{TypeIdPrefix, ValidationError};
use typeid_suffix::prelude::*;

Expand Down Expand Up @@ -81,7 +82,7 @@ use tracing::{debug, instrument, trace};
pub struct MagicTypeId {
prefix: TypeIdPrefix,
suffix: TypeIdSuffix,
string_repr: String,
string_repr: SmolStr,
}

impl Ord for MagicTypeId {
Expand Down Expand Up @@ -115,13 +116,13 @@ impl PartialOrd<MagicTypeId> for str {
// Implement PartialOrd for String
impl PartialOrd<String> for MagicTypeId {
fn partial_cmp(&self, other: &String) -> Option<Ordering> {
self.string_repr.partial_cmp(other)
self.string_repr.as_str().partial_cmp(other.as_str())
}
}

impl PartialOrd<MagicTypeId> for String {
fn partial_cmp(&self, other: &MagicTypeId) -> Option<Ordering> {
self.partial_cmp(&other.string_repr)
self.as_str().partial_cmp(other.string_repr.as_str())
}
}

Expand Down Expand Up @@ -178,11 +179,11 @@ impl MagicTypeId {
let string_repr = if prefix.is_empty() {
#[cfg(feature = "instrument")]
trace!("Creating MagicTypeId with empty prefix");
suffix.to_string()
suffix.to_smolstr()
} else {
#[cfg(feature = "instrument")]
trace!("Creating MagicTypeId with prefix and suffix");
format!("{prefix}_{suffix}")
format_smolstr!("{prefix}_{suffix}")
};
#[cfg(feature = "instrument")]
debug!("Created MagicTypeId: {}", string_repr);
Expand Down Expand Up @@ -253,7 +254,7 @@ impl MagicTypeId {
/// assert_eq!(type_id.as_str(), "user_01h455vb4pex5vsknk084sn02q");
/// ```
#[must_use]
pub const fn as_str(&self) -> &str {
pub fn as_str(&self) -> &str {
self.string_repr.as_str()
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/typeid-prefix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ arbitrary = ["dep:arbitrary"]
serde = ["dep:serde"]

[dependencies]
smol_str = { workspace = true }
arbitrary = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
Expand Down
7 changes: 4 additions & 3 deletions crates/typeid-prefix/src/type_id_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::str::FromStr;

use crate::ValidationError;

use smol_str::{SmolStr, ToSmolStr};
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};

Expand All @@ -30,7 +31,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// ```
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TypeIdPrefix(String);
pub struct TypeIdPrefix(SmolStr);

#[cfg(feature = "serde")]
impl Serialize for TypeIdPrefix {
Expand Down Expand Up @@ -237,7 +238,7 @@ impl TypeIdPrefix {
return Err(ValidationError::ContainsInvalidCharacters);
}

Ok(Self(input.to_string()))
Ok(Self(input.to_smolstr()))
}

pub(crate) fn clean_inner(input: &str) -> String {
Expand Down Expand Up @@ -273,7 +274,7 @@ impl TypeIdPrefix {
/// assert_eq!(prefix.as_str(), "valid_prefix");
/// ```
#[must_use]
pub const fn as_str(&self) -> &str {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
Expand Down