Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impls for serde_json and rmp-serde #18

Merged
merged 4 commits into from
Sep 8, 2024
Merged
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
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ numpy = { version = "0.21", optional = true }
pyo3 = { version = ">=0.21", optional = true }
uuid = { version = "1", optional = true }
either = { version = ">=1", default-features = false, optional = true }
serde_json = { version = ">=1", default-features = false, optional = true, features = ["std"] }
rmp-serde = { version = ">=1", default-features = false, optional = true }

[dev-dependencies]
trybuild = { version = "1.0", features = ["diff"] }
Expand All @@ -53,6 +55,12 @@ uuid = ["dep:uuid"]
# Provides `Transient` implementations for `either` types
either = ["dep:either"]

# Provides `Transient` implementations for `serde_json` types
serde_json = ["dep:serde_json"]

# Provides `Transient` implementations for `rmp_serde` types
rmp-serde = ["dep:rmp-serde"]

[workspace.lints.clippy]
let_unit_value = "warn"
manual_assert = "warn"
Expand Down
15 changes: 15 additions & 0 deletions src/transient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,18 @@ mod either_impls {
type Transience = (Covariant<L>, Covariant<R>);
}
}

#[cfg(feature = "serde_json")]
mod serde_json_impls {
use serde_json::Error;

impl crate::Static for Error {}
}

#[cfg(feature = "rmp-serde")]
mod rmp_serde_impls {
use rmp_serde::{decode, encode};

impl crate::Static for encode::Error {}
impl crate::Static for decode::Error {}
}
2 changes: 1 addition & 1 deletion tests/fail/invariance-bad-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ unsafe impl<'a> Transient for S<'a> {

// This function requires `long` to shorten its lifetime from 'b to 'a, and
// should be *rejected* if the type is considered to be *invariant*.
fn shrink<'a, 'b: 'a>(long: Box<S<'b>>) -> Box<dyn Any<Inv<'a>> + '_> {
fn shrink<'a, 'b: 'a>(long: Box<S<'b>>) -> Box<dyn Any<Inv<'a>> + 'b> {
long
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fail/invariance-bad-function.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: lifetime may not live long enough
--> tests/fail/invariance-bad-function.rs:15:5
|
14 | fn shrink<'a, 'b: 'a>(long: Box<S<'b>>) -> Box<dyn Any<Inv<'a>> + '_> {
14 | fn shrink<'a, 'b: 'a>(long: Box<S<'b>>) -> Box<dyn Any<Inv<'a>> + 'b> {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
Expand Down
Loading