Struct scylla_cql::types::serialize::writers::CellWriter
source · pub struct CellWriter<'buf> { /* private fields */ }
Expand description
Represents a handle to a CQL value that needs to be written into.
The writer can either be transformed into a ready value right away
(via set_null
,
set_unset
or set_value
or transformed into
the CellValueBuilder
in order to gradually initialize
the value when the contents are not available straight away.
After the value is fully initialized, the handle is consumed and
a WrittenCellProof
object is returned
in its stead. This is a type-level proof that the value was fully initialized
and is used in SerializeValue::serialize
in order to enforce the implementer to fully initialize the provided handle
to CQL value.
Dropping this type without calling any of its methods will result in nothing being written.
Implementations§
source§impl<'buf> CellWriter<'buf>
impl<'buf> CellWriter<'buf>
sourcepub fn new(buf: &'buf mut Vec<u8>) -> Self
pub fn new(buf: &'buf mut Vec<u8>) -> Self
Creates a new cell writer based on an existing Vec.
The newly created row writer will append data to the end of the vec.
sourcepub fn set_null(self) -> WrittenCellProof<'buf>
pub fn set_null(self) -> WrittenCellProof<'buf>
Sets this value to be null, consuming this object.
sourcepub fn set_unset(self) -> WrittenCellProof<'buf>
pub fn set_unset(self) -> WrittenCellProof<'buf>
Sets this value to represent an unset value, consuming this object.
sourcepub fn set_value(
self,
contents: &[u8],
) -> Result<WrittenCellProof<'buf>, CellOverflowError>
pub fn set_value( self, contents: &[u8], ) -> Result<WrittenCellProof<'buf>, CellOverflowError>
Sets this value to a non-zero, non-unset value with given contents.
Prefer this to into_value_builder
if you have all of the contents of the value ready up front (e.g. for
fixed size types).
Fails if the contents size overflows the maximum allowed CQL cell size (which is i32::MAX).
sourcepub fn into_value_builder(self) -> CellValueBuilder<'buf>
pub fn into_value_builder(self) -> CellValueBuilder<'buf>
Turns this writter into a CellValueBuilder
which can be used
to gradually initialize the CQL value.
This method should be used if you don’t have all of the data up front, e.g. when serializing compound types such as collections or UDTs.