risingwave_common/types/
serial.rsuse std::error::Error;
use std::hash::Hash;
use bytes::BytesMut;
use postgres_types::{accepts, to_sql_checked, IsNull, ToSql, Type};
use risingwave_common_estimate_size::ZeroHeapSize;
use serde::{Serialize, Serializer};
use crate::util::row_id::RowId;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Default, Hash)]
pub struct Serial(pub(crate) i64);
impl From<Serial> for i64 {
fn from(value: Serial) -> i64 {
value.0
}
}
impl From<i64> for Serial {
fn from(value: i64) -> Self {
Self(value)
}
}
impl ZeroHeapSize for Serial {}
impl Serial {
#[inline]
pub fn into_inner(self) -> i64 {
self.0
}
#[inline]
pub fn as_row_id(self) -> RowId {
self.0 as RowId
}
}
impl Serialize for Serial {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_i64(self.0)
}
}
impl crate::types::to_text::ToText for Serial {
fn write<W: std::fmt::Write>(&self, f: &mut W) -> std::fmt::Result {
write!(f, "{}", self.0)
}
fn write_with_type<W: std::fmt::Write>(
&self,
_ty: &crate::types::DataType,
f: &mut W,
) -> std::fmt::Result {
self.write(f)
}
}
impl ToSql for Serial {
accepts!(INT8);
to_sql_checked!();
fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where
Self: Sized,
{
self.0.to_sql(ty, out)
}
}