meilisearch/meilisearch-schema/src/lib.rs

71 lines
1.4 KiB
Rust
Raw Normal View History

2020-01-11 01:20:30 +08:00
mod error;
mod fields_map;
mod schema;
2020-01-11 01:20:30 +08:00
pub use error::{Error, SResult};
2020-01-14 02:10:58 +08:00
pub use fields_map::FieldsMap;
pub use schema::Schema;
2019-10-18 19:05:28 +08:00
use serde::{Deserialize, Serialize};
2020-01-11 01:20:30 +08:00
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
2020-01-14 02:10:58 +08:00
pub struct IndexedPos(pub u16);
2020-01-14 02:10:58 +08:00
impl IndexedPos {
pub const fn new(value: u16) -> IndexedPos {
IndexedPos(value)
}
2020-01-14 02:10:58 +08:00
pub const fn min() -> IndexedPos {
IndexedPos(u16::min_value())
}
2020-01-14 02:10:58 +08:00
pub const fn max() -> IndexedPos {
IndexedPos(u16::max_value())
}
2019-09-04 22:32:55 +08:00
}
2020-01-14 02:10:58 +08:00
impl From<u16> for IndexedPos {
fn from(value: u16) -> IndexedPos {
IndexedPos(value)
2020-01-08 21:17:38 +08:00
}
}
2020-01-14 02:10:58 +08:00
impl Into<u16> for IndexedPos {
2020-01-11 01:20:30 +08:00
fn into(self) -> u16 {
self.0
2020-01-08 21:17:38 +08:00
}
}
2020-01-14 02:10:58 +08:00
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
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)
}
}
impl Into<u16> for FieldId {
fn into(self) -> u16 {
self.0
}
}