Trait serde_db::de::DeserializableResultset
source · pub trait DeserializableResultset: Sized {
type E: From<DeserializationError> + Sized;
type ROW: DeserializableRow;
// Required methods
fn has_multiple_rows(&mut self) -> DeserializationResult<bool>;
fn next(&mut self) -> DeserializationResult<Option<Self::ROW>>;
fn number_of_fields(&self) -> usize;
fn fieldname(&self, field_idx: usize) -> Option<&str>;
// Provided method
fn try_into<'de, T>(self) -> Result<T, Self::E>
where T: Deserialize<'de> { ... }
}
Expand description
Interface for a database resultset to support deserialization.
Required Associated Types§
sourcetype E: From<DeserializationError> + Sized
type E: From<DeserializationError> + Sized
Error type of the database driver.
sourcetype ROW: DeserializableRow
type ROW: DeserializableRow
Concrete type for the DB row, which must implement DeserializabeRow
.
Required Methods§
sourcefn has_multiple_rows(&mut self) -> DeserializationResult<bool>
fn has_multiple_rows(&mut self) -> DeserializationResult<bool>
Returns true if more than one row is contained, including eventually not yet fetched rows.
Errors
E.g. fetching can fail.
sourcefn next(&mut self) -> DeserializationResult<Option<Self::ROW>>
fn next(&mut self) -> DeserializationResult<Option<Self::ROW>>
Removes the next row and returns it, or None if the result set is empty, or an error.
Errors
E.g. fetching can fail.
sourcefn number_of_fields(&self) -> usize
fn number_of_fields(&self) -> usize
Returns the number of fields in each (complete) row.
Provided Methods§
sourcefn try_into<'de, T>(self) -> Result<T, Self::E>where
T: Deserialize<'de>,
fn try_into<'de, T>(self) -> Result<T, Self::E>where T: Deserialize<'de>,
A provided method that translates a resultset into a given rust type
that implements serde::Deserialize
.
The type of the target variable needs to be specified explicitly, so that
try_into()
can derive the type it needs to serialize into:
#[derive(Deserialize)]
struct MyStruct {
...
}
let typed_result: Vec<MyStruct> = resultset.try_into()?;
Errors
An error is produced if deserialization into the target type is not possible, or if fetching fails.