Skip to content

Commit

Permalink
improve struct typing data with FrcType
Browse files Browse the repository at this point in the history
  • Loading branch information
oh-yes-0-fps committed Aug 23, 2024
1 parent 7996d7f commit 79be7ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frclib-core"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
description = "A collection of utilities to be used across the FRC in rust ecosystem"
Expand Down Expand Up @@ -34,7 +34,7 @@ paste = { version = "1.0.15", optional = true }
approx = "0.5.1"

[features]
structure = ["inventory", "frclib-structure-macros"]
structure = ["inventory", "frclib-structure-macros", "num"]
value-union = ["structure", "serde", "rmpv", "serde_json"]
units = ["num", "nalgebra", "simba", "serde", "paste"]
time = ["ctor"]
Expand Down
10 changes: 8 additions & 2 deletions src/structure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod prims;

// use logos::Logos;

use std::io::Cursor;
use std::{hash::Hash, io::Cursor};

pub use inventory;

Expand All @@ -24,6 +24,12 @@ pub struct FrcStructDesc {
pub size: usize,
}

impl Hash for FrcStructDesc {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.type_str.hash(state);
}
}

inventory::collect!(FrcStructDesc);

/// A global database of structure descriptions
Expand Down Expand Up @@ -139,7 +145,7 @@ impl FrcStructureBytes {
}

/// A set length string of characters
pub type StructString<const N: usize> = [char; N];
pub type FixedString<const N: usize> = [char; N];

// #[derive(Clone, Copy, Debug, PartialEq, Eq)]
// pub(crate) enum StructureFieldTypes {
Expand Down
14 changes: 7 additions & 7 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod test;
mod trait_impls;
mod traits;

use crate::structure::{FrcStructure, FrcStructureBytes};
use crate::structure::{FrcStructDesc, FrcStructure, FrcStructureBytes};
pub use error::FrcValueCastError;
pub use traits::IntoFrcValue;
pub use traits::StaticallyFrcTyped;
Expand Down Expand Up @@ -41,8 +41,8 @@ pub enum FrcType {
FloatArray,
DoubleArray,
StringArray,
Struct,
StructArray,
Struct(&'static FrcStructDesc),
StructArray(&'static FrcStructDesc),
}
impl Display for FrcType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand All @@ -59,8 +59,8 @@ impl Display for FrcType {
Self::DoubleArray => write!(f, "DoubleArray"),
Self::StringArray => write!(f, "StringArray"),
Self::Raw => write!(f, "Raw"),
Self::Struct => write!(f, "Struct"),
Self::StructArray => write!(f, "StructArray"),
Self::Struct(desc) => write!(f, "Struct({})", desc.type_str),
Self::StructArray(desc) => write!(f, "StructArray({})", desc.type_str),
}
}
}
Expand Down Expand Up @@ -181,8 +181,8 @@ impl FrcValue {
Self::DoubleArray(_) => FrcType::DoubleArray,
Self::StringArray(_) => FrcType::StringArray,
Self::Raw(_) => FrcType::Raw,
Self::Struct(_) => FrcType::Struct,
Self::StructArray(_) => FrcType::StructArray,
Self::Struct(s) => FrcType::Struct(s.desc),
Self::StructArray(s) => FrcType::StructArray(s.desc),
}
}
///Creates an empty Binary
Expand Down

0 comments on commit 79be7ed

Please sign in to comment.