Initial commit
This commit is contained in:
commit
0bbcab5727
24 changed files with 1416 additions and 0 deletions
6
type-map/Cargo.toml
Normal file
6
type-map/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "type-map"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
28
type-map/src/lib.rs
Normal file
28
type-map/src/lib.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct CommTypeId(pub u8);
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct DataTypeId(pub u16);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Version(pub u16);
|
||||
|
||||
/// A single protocol version's type dictionary.
|
||||
/// Compiled into the client, or loaded by the host via the registry.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TypeMap {
|
||||
pub version: Version,
|
||||
pub comm_types: HashMap<String, u8>,
|
||||
pub data_types: HashMap<String, u16>,
|
||||
}
|
||||
|
||||
impl TypeMap {
|
||||
pub fn comm_id(&self, name: &str) -> Option<u8> {
|
||||
self.comm_types.get(name).copied()
|
||||
}
|
||||
pub fn data_id(&self, name: &str) -> Option<u16> {
|
||||
self.data_types.get(name).copied()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue