Expand description
ForgeDB Types
Core type definitions for ForgeDB schemas and generated code.
§Overview
This crate provides type definitions that match ForgeDB’s schema language types, enabling type-safe serialization, validation, and storage operations. It is a foundational crate used by generated code and other ForgeDB runtime libraries.
§Architecture
The crate is designed around two key concepts:
- Primitive Types: Direct mappings of ForgeDB schema types to Rust types
- Generic Value Enum: Runtime type information for heterogeneous data
All types are designed for zero or minimal overhead with #[repr(transparent)]
for wrapper types and efficient serialization using Serde derive macros.
§Supported Types
| ForgeDB Type | Rust Type | Description |
|---|---|---|
u32 | u32 | 32-bit unsigned integer |
u64 | u64 | 64-bit unsigned integer |
i32 | i32 | 32-bit signed integer |
i64 | i64 | 64-bit signed integer |
f64 | f64 | 64-bit floating point |
bool | bool | Boolean value |
string | String | UTF-8 encoded text |
uuid | Uuid | Universally unique identifier |
timestamp | Timestamp | Unix timestamp (seconds since epoch) |
§Examples
§Basic Usage
use forgedb_types::{Value, Timestamp, Uuid};
// Create a timestamp from the current time
let ts = Timestamp::now();
println!("Current timestamp: {}", ts.as_seconds());
// Work with generic values
let values = vec![
Value::I32(42),
Value::String("hello".to_string()),
Value::Uuid(Uuid::new_v4()),
];
// Serialize to JSON
let json = serde_json::to_string(&values[0]).unwrap();§Type Conversions
use forgedb_types::Value;
// Convenient From implementations
let val: Value = 42_i32.into();
let val: Value = "hello".into();
// Type checking
if val.is_numeric() {
println!("This is a numeric value");
}§Public API
§Core Types
Timestamp- Wrapper aroundi64for Unix timestampsValue- Enum that can hold any ForgeDB primitive typeUuid- Re-exported from theuuidcrate
§Key Methods
Timestamp::now()- Get current timestampTimestamp::from_seconds(i64)- Create from seconds since epochValue::type_name()- Get type name stringValue::is_numeric()- Check if numeric type
§Related Crates
forgedb-storage- Uses these types for columnar storageforgedb-parser- Parses schemas into these types
§See Also
- README for detailed documentation and usage examples
- uuid crate documentation for UUID operations
Structs§
- Timestamp
- Unix timestamp representing seconds since the Unix epoch (January 1, 1970 00:00:00 UTC)
- Uuid
- Re-export uuid for convenience A Universally Unique Identifier (UUID).
Enums§
- Value
- A generic value type that can hold any ForgeDB primitive type