1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#![warn(missing_docs)]
//! Types and traits related to serialization of values to the CQL format.
use std::{error::Error, sync::Arc};
use thiserror::Error;
pub mod batch;
pub mod raw_batch;
pub mod row;
pub mod value;
pub mod writers;
pub use writers::{CellValueBuilder, CellWriter, RowWriter};
/// An error indicating that a failure happened during serialization.
///
/// The error is type-erased so that the crate users can define their own
/// serialization impls and their errors. As for the impls defined or generated
/// by the driver itself, the following errors can be returned:
///
/// - [`row::BuiltinSerializationError`] is returned when serialization of
/// one of types with an impl built into the driver fails. It is also returned
/// from impls generated by the `SerializeRow` macro.
/// - [`value::BuiltinSerializationError`] is analogous to the above but is
/// returned from [`SerializeValue::serialize`](value::SerializeValue::serialize)
/// instead both in the case of builtin impls and impls generated by the
/// `SerializeValue` macro. It won't be returned by the `Session` directly,
/// but it might be nested in the [`row::BuiltinSerializationError`].
/// - [`row::ValueListToSerializeRowAdapterError`] is returned in case when
/// a list of named values encoded with the legacy `ValueList` trait is passed
/// as an argument to the statement, and rewriting it using the new
/// `SerializeRow` interface fails.
// TODO: remove mentions about legacy errors from the above description when
// they are removed.
#[derive(Debug, Clone, Error)]
#[error("SerializationError: {0}")]
pub struct SerializationError(Arc<dyn Error + Send + Sync>);
impl SerializationError {
/// Constructs a new `SerializationError`.
#[inline]
pub fn new(err: impl Error + Send + Sync + 'static) -> SerializationError {
SerializationError(Arc::new(err))
}
/// Retrieve an error reason by downcasting to specific type.
pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> {
self.0.downcast_ref()
}
}