oxedyne/fe2o3/fe2o3_steel/src/srv/id.rs
1.1 KiB, 5 runs
created by r1870400018:989, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use oxedyne_fe2o3_core::prelude::*; |
| 2 | use oxedyne_fe2o3_jdat::{ |
| 3 | id::IdDat, |
| 4 | kind::Kind, |
| 5 | }; |
| 6 | |
| 7 | use std::{ |
| 8 | fmt, |
| 9 | mem, |
| 10 | }; |
| 11 | |
| 12 | |
| 13 | //// Protocol identifier types for defaults and testing. |
| 14 | pub type BidTyp = u64; // Bot Id |
| 15 | pub type SidTyp = u64; // State Id (e.g. for sessions) |
| 16 | pub type UidTyp = u128; // User Id, a default. |
| 17 | |
| 18 | pub const UID_KIND: Kind = Kind::U128; |
| 19 | |
| 20 | pub const BID_LEN: usize = mem::size_of::<BidTyp>(); |
| 21 | pub const SID_LEN: usize = mem::size_of::<SidTyp>(); |
| 22 | pub const UID_LEN: usize = mem::size_of::<UidTyp>(); |
| 23 | |
| 24 | pub type Bid = IdDat<{BID_LEN}, BidTyp>; |
| 25 | pub type Sid = IdDat<{SID_LEN}, SidTyp>; |
| 26 | pub type Uid = IdDat<{UID_LEN}, UidTyp>; |
| 27 | |
| 28 | // Message command identifier. |
| 29 | new_type!(McidTyp, u64, Clone, Copy); |
| 30 | |
| 31 | pub const MCID_KIND: Kind = Kind::U64; |
| 32 | |
| 33 | impl fmt::Display for McidTyp { |
| 34 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 35 | write!(f, "{:016x}", self) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl fmt::Debug for McidTyp { |
| 40 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 41 | write!(f, "{}", self) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl fmt::LowerHex for McidTyp { |
| 46 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 47 | fmt::LowerHex::fmt(&self.0, f) |
| 48 | } |
| 49 | } |