pub struct Json<T: ?Sized>(pub T);
Expand description
Json for json and jsonb fields
Will attempt to cast to type passed in as the generic.
[dependencies]
serde_json = { version = "1.0", features = ["raw_value"] }
Example
#[derive(Deserialize)]
struct Book {
name: String
}
#[derive(sqlx::FromRow)]
struct Author {
name: String,
books: sqlx::types::Json<Book>
}
Can also be used to turn the json/jsonb into a hashmap
use std::collections::HashMap;
use serde::Deserialize;
#[derive(Deserialize)]
struct Book {
name: String
}
#[derive(sqlx::FromRow)]
struct Library {
id: String,
dewey_decimal: sqlx::types::Json<HashMap<String, Book>>
}
Tuple Fields§
§0: T
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Json<T>where
T: Deserialize<'de> + ?Sized,
impl<'de, T> Deserialize<'de> for Json<T>where
T: Deserialize<'de> + ?Sized,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: PartialEq + ?Sized> PartialEq for Json<T>
impl<T: PartialEq + ?Sized> PartialEq for Json<T>
source§impl<T: PartialOrd + ?Sized> PartialOrd for Json<T>
impl<T: PartialOrd + ?Sized> PartialOrd for Json<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Copy + ?Sized> Copy for Json<T>
impl<T: Eq + ?Sized> Eq for Json<T>
impl<T: ?Sized> StructuralEq for Json<T>
impl<T: ?Sized> StructuralPartialEq for Json<T>
Auto Trait Implementations§
impl<T: ?Sized> RefUnwindSafe for Json<T>where
T: RefUnwindSafe,
impl<T: ?Sized> Send for Json<T>where
T: Send,
impl<T: ?Sized> Sync for Json<T>where
T: Sync,
impl<T: ?Sized> Unpin for Json<T>where
T: Unpin,
impl<T: ?Sized> UnwindSafe for Json<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.