-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: move from #1875 * test: `ManuallyDrop` * fix: `Reflection` * chore: remove unused imports * fix: miri
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ mod bool; | |
mod cmp; | ||
mod floating; | ||
mod integral; | ||
mod mem; | ||
mod non_zero; | ||
mod string; | ||
mod unit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use core::mem::ManuallyDrop; | ||
|
||
use error_stack::Result; | ||
|
||
use crate::{error::DeserializeError, Deserialize, Deserializer}; | ||
|
||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for ManuallyDrop<T> { | ||
type Reflection = T::Reflection; | ||
|
||
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, DeserializeError> { | ||
T::deserialize(de).map(Self::new) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use core::mem::ManuallyDrop; | ||
|
||
use deer::Deserialize; | ||
use deer_desert::{assert_tokens, Token}; | ||
use proptest::prelude::*; | ||
use serde::Serialize; | ||
use similar_asserts::assert_serde_eq; | ||
|
||
#[cfg(not(miri))] | ||
proptest! { | ||
#[test] | ||
fn manually_drop_ok(value in any::<u8>()) { | ||
assert_tokens(&ManuallyDrop::new(value), &[Token::Number(value.into())]); | ||
} | ||
} | ||
|
||
fn assert_json(lhs: impl Serialize, rhs: impl Serialize) { | ||
let lhs = serde_json::to_value(lhs).expect("should be able to serialize lhs"); | ||
let rhs = serde_json::to_value(rhs).expect("should be able to serialize rhs"); | ||
|
||
assert_serde_eq!(lhs, rhs); | ||
} | ||
|
||
// test that the `Reflection` of all types are the same as their underlying type | ||
#[test] | ||
fn manually_drop_reflection_same() { | ||
let lhs = ManuallyDrop::<u8>::reflection(); | ||
let rhs = u8::reflection(); | ||
|
||
assert_json(lhs, rhs); | ||
} |