Skip to content

Commit

Permalink
Add std types for Rocket (and uuid)
Browse files Browse the repository at this point in the history
  • Loading branch information
the10thWiz committed Jun 29, 2024
1 parent 28daef7 commit 9b03464
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ transient-derive = { path = "derive", version = "0.3", optional = true }
ndarray = { version = "0.15", optional = true }
numpy = { version = "0.21", optional = true }
pyo3 = { version = ">=0.21", optional = true }
uuid = { version = "1", optional = true }

[dev-dependencies]
trybuild = { version = "1.0.49", features = ["diff"] }
Expand All @@ -42,6 +43,7 @@ pyo3 = ["dep:pyo3"]

# Provides `Transient` implementations for `numpy` types
numpy = ["dep:numpy", "ndarray", "pyo3"]
uuid = ["dep:uuid"]

[workspace.lints.clippy]
let_unit_value = "warn"
Expand Down
21 changes: 20 additions & 1 deletion src/transient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,12 @@ mod std_impls {

use std::any::Any as StdAny;
use std::borrow::{Cow, ToOwned};
use std::char::ParseCharError;
use std::collections::HashMap;
use std::net::AddrParseError;
use std::num::{ParseFloatError, ParseIntError};
use std::str::ParseBoolError;
use std::string::ParseError;

macro_rules! impl_refs {
{
Expand Down Expand Up @@ -431,14 +436,18 @@ mod std_impls {
impl_primatives! {
isize, i8, i16, i32, i64, i128,
usize, u8, u16, u32, u64, u128,
f32, f64, String, Box<str>, ()
f32, f64, String, Box<str>, (),
ParseIntError, ParseCharError,
ParseFloatError, ParseBoolError,
ParseError, AddrParseError,
}

unsafe impl<'a> Transient for &'a str {
type Static = &'static str;
type Transience = Co<'a>;
}
impl_refs!(&'a str ['a]);
impl Static for str {}

unsafe impl<'a, T: Transient> Transient for &'a [T] {
type Static = &'static [T::Static];
Expand Down Expand Up @@ -596,3 +605,13 @@ mod numpy_impls {
type Transience = crate::Co<'py>;
}
}

#[cfg(feature = "uuid")]
mod uuid_impls {
use super::Static;
use uuid::*;
impl Static for Uuid {}
impl Static for Error {}
impl Static for Variant {}
impl Static for Version {}
}

0 comments on commit 9b03464

Please sign in to comment.