| Crates.io | stdb-common |
| lib.rs | stdb-common |
| version | 0.1.0 |
| created_at | 2025-07-10 03:55:07.145041+00 |
| updated_at | 2025-07-10 03:55:07.145041+00 |
| description | Core utilities and common functionality for SpacetimeDB-based game development. |
| homepage | https://github.com/rafaelGuerreiro/spacetimedb-libs |
| repository | https://github.com/rafaelGuerreiro/spacetimedb-libs |
| max_upload_size | |
| id | 1745809 |
| size | 44,069 |
Core utilities and common functionality for SpacetimeDB-based game development. This library provides essential building blocks including validation, error handling, and UUID generation.
u8, u16, u32, u64, u128, usize)ValidationError enum with specific error typesErrorMapper trait for consistent error transformationServiceResult<T> type alias for standardized error handlinguse stdb_common::{validate_str, validate_u32, ServiceResult};
fn create_player(name: &str, level: u32) -> ServiceResult<()> {
validate_str("name", name, 3, 20)?;
validate_u32("level", level, 1, 100)?;
Ok(())
}
use stdb_common::{UuidExt, Uuid};
use spacetimedb::ReducerContext;
fn create_unique_id(ctx: &ReducerContext) -> Uuid {
// Random UUID v4
let random_id = ctx.new_uuid_v4();
// Timestamp-based UUID v7
let timestamp_id = ctx.new_uuid_v7();
random_id
}
use stdb_common::ReducerContextRequirements;
use spacetimedb::ReducerContext;
fn admin_only_operation(ctx: &ReducerContext) -> ServiceResult<()> {
ctx.require_private_access()?;
// Perform admin operation
Ok(())
}
RequiredField: Field is required but emptyFieldTooSmall: Value is below minimum thresholdFieldTooLarge: Value exceeds maximum thresholdvalidate_str(name, value, min_length, max_length): Validates string lengthvalidate_u8/u16/u32/u64/u128/usize(name, value, min_value, max_value): Validates numeric rangesUuidExt: Extends ReducerContext with UUID generation methodsReducerContextRequirements: Provides access control validationErrorMapper: Maps errors to ServiceErrorUuid: String representation of UUIDServiceResult<T>: Result type with ServiceErrorValidationError: Validation-specific error enumThe library includes comprehensive unit tests covering:
Run tests with:
cd server
cargo +nightly fmt && cargo check --all && cargo test