use std::{ffi::c_char, marker::PhantomData};
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TimestampNs(pub u64);
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Decimal {
pub raw: i64,
pub scale: i8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Labels {
pub name: &'static str,
pub values: &'static [(u16, &'static str)],
}
pub trait EnumField: Copy {
type Repr: Copy;
type Storage: Copy;
const TYPE_ID: u8;
const NAME: &'static str;
const LABELS: &'static [(u16, &'static str)];
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct OpenEnum<E: EnumField> {
raw: E::Repr,
_marker: PhantomData<E>,
}
impl<E: EnumField> OpenEnum<E> {
pub const fn from_raw(raw: E::Repr) -> Self {
Self {
raw,
_marker: PhantomData,
}
}
pub const fn raw(&self) -> E::Repr {
self.raw
}
}
impl<E> OpenEnum<E>
where
E: EnumField + TryFrom<E::Repr>,
E::Repr: std::fmt::Display,
{
pub fn get(&self) -> crate::Result<E> {
E::try_from(self.raw).map_err(|_| crate::Error::conversion::<E>(self.raw))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Char(pub c_char);
#[derive(Clone, Copy)]
pub enum CStr {}
#[derive(Clone, Copy)]
pub enum Symbol {}