Skip to content

Commit 8a7e259

Browse files
committed
fix(errors): add Clone trait to MagicTypeIdError and ValidationError
Add Clone derive to MagicTypeIdError and ValidationError to ensure all custom error types implement the standard traits expected of Rust errors. Also made as_str() methods const in TypeIdPrefix and MagicTypeId, removing the previous clippy allow directives. Bumps typeid_prefix to 1.2.1 and mti to 1.1.1.
1 parent 6ce80b4 commit 8a7e259

6 files changed

Lines changed: 8 additions & 10 deletions

File tree

crates/mti/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mti"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
edition.workspace = true
55
authors.workspace = true
66
description = "Generates human-readable, prefixed, and globally unique identifiers (based on the TypeID spec) for Rust. Improves clarity, type-safety, debugging, and identifier management in your applications."

crates/mti/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing::{error, instrument};
1515
///
1616
/// This enum encapsulates errors from both the prefix and suffix components
1717
/// of a `MagicTypeId`, allowing for more specific error handling.
18-
#[derive(Debug, PartialEq, Eq)]
18+
#[derive(Debug, Clone, PartialEq, Eq)]
1919
pub enum MagicTypeIdError {
2020
/// Errors related to the `TypeID` prefix.
2121
///

crates/mti/src/magic_type_id.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,8 @@ impl MagicTypeId {
253253
/// assert_eq!(type_id.as_str(), "user_01h455vb4pex5vsknk084sn02q");
254254
/// ```
255255
#[must_use]
256-
#[allow(clippy::missing_const_for_fn)]
257-
pub fn as_str(&self) -> &str {
258-
&self.string_repr
256+
pub const fn as_str(&self) -> &str {
257+
self.string_repr.as_str()
259258
}
260259
}
261260

crates/typeid-prefix/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typeid_prefix"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
edition.workspace = true
55
authors.workspace = true
66
description = "A Rust library that implements a type-safe version of the TypePrefix section of the `TypeID` Specification"

crates/typeid-prefix/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt;
44
///
55
/// This enum encapsulates various error conditions that may arise when validating
66
/// a `TypeID` prefix according to the `TypeID` specification.
7-
#[derive(Debug, PartialEq, Eq)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
88
pub enum ValidationError {
99
/// The input exceeds the maximum allowed length of 63 characters.
1010
ExceedsMaxLength,

crates/typeid-prefix/src/type_id_prefix.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@ impl TypeIdPrefix {
273273
/// assert_eq!(prefix.as_str(), "valid_prefix");
274274
/// ```
275275
#[must_use]
276-
#[allow(clippy::missing_const_for_fn)]
277-
pub fn as_str(&self) -> &str {
278-
&self.0
276+
pub const fn as_str(&self) -> &str {
277+
self.0.as_str()
279278
}
280279
}
281280

0 commit comments

Comments
 (0)