scylla_cql/serialize/
mod.rs

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