Skip to main content

Crate forgedb_types

Crate forgedb_types 

Source
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 TypeRust TypeDescription
u32u3232-bit unsigned integer
u64u6464-bit unsigned integer
i32i3232-bit signed integer
i64i6464-bit signed integer
f64f6464-bit floating point
boolboolBoolean value
stringStringUTF-8 encoded text
uuidUuidUniversally unique identifier
timestampTimestampUnix 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 around i64 for Unix timestamps
  • Value - Enum that can hold any ForgeDB primitive type
  • Uuid - Re-exported from the uuid crate

§Key Methods

  • Timestamp::now() - Get current timestamp
  • Timestamp::from_seconds(i64) - Create from seconds since epoch
  • Value::type_name() - Get type name string
  • Value::is_numeric() - Check if numeric type

§See Also

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