Struct scylla_cql::frame::value::CqlVarint
source · pub struct CqlVarint(/* private fields */);
Expand description
Native CQL varint
representation.
Represented as two’s-complement binary in big-endian order.
This type is a raw representation in bytes. It’s the default
implementation of varint
type - independent of any
external crates and crate features.
The type is not very useful in most use cases.
However, users can make use of more complex types
such as num_bigint::BigInt
(v0.3/v0.4).
The library support (e.g. conversion from CqlValue
) for these types is
enabled via num-bigint-03
and num-bigint-04
crate features.
§DB data format
Notice that constructors don’t perform any normalization on the provided data. This means that underlying bytes may contain leading zeros.
Currently, Scylla and Cassandra support non-normalized varint
values.
Bytes provided by the user via constructor are passed to DB as is.
The implementation of PartialEq
, however, normalizes the underlying bytes
before comparison. For details, check examples.
Implementations§
source§impl CqlVarint
impl CqlVarint
Constructors from bytes
sourcepub fn from_signed_bytes_be(digits: Vec<u8>) -> Self
pub fn from_signed_bytes_be(digits: Vec<u8>) -> Self
Creates a CqlVarint
from an array of bytes in
two’s complement big-endian binary representation.
See: disclaimer about non-normalized values.
sourcepub fn from_signed_bytes_be_slice(digits: &[u8]) -> Self
pub fn from_signed_bytes_be_slice(digits: &[u8]) -> Self
Creates a CqlVarint
from a slice of bytes in
two’s complement binary big-endian representation.
See: disclaimer about non-normalized values.
source§impl CqlVarint
impl CqlVarint
Conversion to bytes
sourcepub fn into_signed_bytes_be(self) -> Vec<u8>
pub fn into_signed_bytes_be(self) -> Vec<u8>
Converts CqlVarint
to an array of bytes in two’s
complement binary big-endian representation.
sourcepub fn as_signed_bytes_be_slice(&self) -> &[u8] ⓘ
pub fn as_signed_bytes_be_slice(&self) -> &[u8] ⓘ
Returns a slice of bytes in two’s complement binary big-endian representation.
Trait Implementations§
source§impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for CqlVarint
impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for CqlVarint
source§fn type_check(typ: &ColumnType<'_>) -> Result<(), TypeCheckError>
fn type_check(typ: &ColumnType<'_>) -> Result<(), TypeCheckError>
source§fn deserialize(
typ: &'metadata ColumnType<'metadata>,
v: Option<FrameSlice<'frame>>,
) -> Result<Self, DeserializationError>
fn deserialize( typ: &'metadata ColumnType<'metadata>, v: Option<FrameSlice<'frame>>, ) -> Result<Self, DeserializationError>
source§impl FromCqlVal<CqlValue> for CqlVarint
impl FromCqlVal<CqlValue> for CqlVarint
source§impl PartialEq for CqlVarint
impl PartialEq for CqlVarint
Compares two CqlVarint
values after normalization.
§Example
let non_normalized_bytes = vec![0x00, 0x01];
let normalized_bytes = vec![0x01];
assert_eq!(
CqlVarint::from_signed_bytes_be(non_normalized_bytes),
CqlVarint::from_signed_bytes_be(normalized_bytes)
);
source§impl SerializeValue for CqlVarint
impl SerializeValue for CqlVarint
source§fn serialize<'b>(
&self,
typ: &ColumnType<'_>,
writer: CellWriter<'b>,
) -> Result<WrittenCellProof<'b>, SerializationError>
fn serialize<'b>( &self, typ: &ColumnType<'_>, writer: CellWriter<'b>, ) -> Result<WrittenCellProof<'b>, SerializationError>
impl Emptiable for CqlVarint
impl Eq for CqlVarint
Auto Trait Implementations§
impl Freeze for CqlVarint
impl RefUnwindSafe for CqlVarint
impl Send for CqlVarint
impl Sync for CqlVarint
impl Unpin for CqlVarint
impl UnwindSafe for CqlVarint
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)