Full split of lang.rs

This commit is contained in:
micialware committed 2026-08-24 11:35:37 +03:00
1 parent 22b455a640
commit c67663141f
17 files changed
+81 -78

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
pub mod entities;
use std::fmt::{Display, Formatter};
use std::num::ParseIntError;
use std::str::FromStr;
use rusqlite::ToSql;
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy, Ord, PartialOrd)]
pub struct Id(pub(crate) u32);
pub const INVALID_ID: Id = Id(0);
impl FromStr for Id {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Id(s.parse::<u32>()?))
}
}
impl From<u32> for Id {
fn from(value: u32) -> Self {
Id(value)
}
}
impl From<Id> for u32 {
fn from(value: Id) -> Self {
value.0
}
}
impl Display for Id {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl FromSql for Id {
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
match value {
ValueRef::Integer(i) => Ok(Id(i as u32)),
_ => Err(FromSqlError::InvalidType),
}
}
}
impl ToSql for Id {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
Ok(ToSqlOutput::from(self.0 as i64))
}
}
impl From<Id> for String {
fn from(value: Id) -> Self {
value.0.to_string()
}
}
impl Id {
pub(crate) fn is_valid(self) -> bool {
self.0 != 0
}
}