75 lines
1.5 KiB
Rust
Raw Normal View History

2020-01-10 18:20:30 +01:00
mod error;
mod fields_map;
mod schema;
2020-01-10 18:20:30 +01:00
pub use error::{Error, SResult};
2020-01-13 19:10:58 +01:00
pub use fields_map::FieldsMap;
pub use schema::Schema;
2019-10-18 13:05:28 +02:00
use serde::{Deserialize, Serialize};
2020-05-05 22:28:46 +02:00
use zerocopy::{AsBytes, FromBytes};
2019-10-18 13:05:28 +02:00
2020-01-10 18:20:30 +01:00
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
2020-01-13 19:10:58 +01:00
pub struct IndexedPos(pub u16);
2020-01-13 19:10:58 +01:00
impl IndexedPos {
pub const fn new(value: u16) -> IndexedPos {
IndexedPos(value)
}
2020-01-13 19:10:58 +01:00
pub const fn min() -> IndexedPos {
IndexedPos(u16::min_value())
}
2020-01-13 19:10:58 +01:00
pub const fn max() -> IndexedPos {
IndexedPos(u16::max_value())
}
2019-09-04 16:32:55 +02:00
}
2020-01-13 19:10:58 +01:00
impl From<u16> for IndexedPos {
fn from(value: u16) -> IndexedPos {
IndexedPos(value)
2020-01-08 14:17:38 +01:00
}
}
2020-01-13 19:10:58 +01:00
impl Into<u16> for IndexedPos {
2020-01-10 18:20:30 +01:00
fn into(self) -> u16 {
self.0
2020-01-08 14:17:38 +01:00
}
}
2020-05-05 22:19:34 +02:00
#[derive(Debug, Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
#[derive(Serialize, Deserialize)]
#[derive(AsBytes, FromBytes)]
#[repr(C)]
2020-01-13 19:10:58 +01:00
pub struct FieldId(pub u16);
impl FieldId {
pub const fn new(value: u16) -> FieldId {
FieldId(value)
}
pub const fn min() -> FieldId {
FieldId(u16::min_value())
}
pub const fn max() -> FieldId {
FieldId(u16::max_value())
}
pub fn next(self) -> SResult<FieldId> {
self.0.checked_add(1).map(FieldId).ok_or(Error::MaxFieldsLimitExceeded)
}
}
impl From<u16> for FieldId {
fn from(value: u16) -> FieldId {
FieldId(value)
}
}
2020-05-05 22:19:34 +02:00
impl From<FieldId> for u16 {
fn from(other: FieldId) -> u16 {
other.0
2020-01-13 19:10:58 +01:00
}
}