use serde::{Deserialize, Serialize};
use std::fmt;
use uuid::Uuid;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub struct TokenId(pub u32);
impl TokenId {
pub const MAX: TokenId = TokenId(u32::MAX);
pub const fn new(value: u32) -> Self {
Self(value)
}
pub const fn get(self) -> u32 {
self.0
}
}
impl From<u32> for TokenId {
fn from(value: u32) -> Self {
TokenId(value)
}
}
impl From<TokenId> for u32 {
fn from(value: TokenId) -> Self {
value.0
}
}
impl From<usize> for TokenId {
fn from(value: usize) -> Self {
TokenId(value as u32)
}
}
impl From<TokenId> for usize {
fn from(value: TokenId) -> Self {
value.0 as usize
}
}
impl fmt::Display for TokenId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct RequestId(pub Uuid);
impl RequestId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for RequestId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for RequestId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct BatchId(pub Uuid);
impl BatchId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for BatchId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for BatchId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ModelId(pub String);
impl ModelId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for ModelId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for ModelId {
fn from(id: String) -> Self {
Self(id)
}
}
impl From<&str> for ModelId {
fn from(id: &str) -> Self {
Self(id.to_string())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct SessionId(pub Uuid);
impl SessionId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for SessionId {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct TaskId(pub Uuid);
impl TaskId {
pub fn new() -> Self {
Self(Uuid::new_v4())
}
}
impl Default for TaskId {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ClientId(pub String);
impl ClientId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for ClientId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for ClientId {
fn from(id: String) -> Self {
Self(id)
}
}
impl From<&str> for ClientId {
fn from(id: &str) -> Self {
Self(id.to_string())
}
}