Skip to content

Commit d3e8ae6

Browse files
committed
Derive all traits and impl Deref and AsRef for types::Json
1 parent c6e9b27 commit d3e8ae6

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

sqlx-core/src/types.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,29 @@ pub mod ipnetwork {
4242
}
4343

4444
#[cfg(feature = "json")]
45-
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
46-
#[derive(Debug, PartialEq)]
47-
pub struct Json<T>(pub T);
45+
pub mod json {
46+
use std::ops::Deref;
47+
48+
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
49+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
50+
pub struct Json<T>(pub T);
51+
52+
impl<T> Deref for Json<T> {
53+
type Target = T;
54+
55+
fn deref(&self) -> &Self::Target {
56+
&self.0
57+
}
58+
}
59+
60+
impl<T> AsRef<T> for Json<T> {
61+
fn as_ref(&self) -> &T {
62+
&self.0
63+
}
64+
}
65+
}
66+
#[cfg(feature = "json")]
67+
pub use self::json::Json;
4868

4969
pub trait TypeInfo: PartialEq<Self> + Debug + Display + Clone {
5070
/// Compares type information to determine if `other` is compatible at the Rust level

0 commit comments

Comments
 (0)