| Crates.io | gltf-v1-derive |
| lib.rs | gltf-v1-derive |
| version | 0.3.0 |
| created_at | 2025-05-27 23:43:46.422691+00 |
| updated_at | 2025-07-28 23:53:18.03079+00 |
| description | Derive macros for gltf-v1 |
| homepage | |
| repository | https://github.com/crazyjackel/asset-importer-rs |
| max_upload_size | |
| id | 1692105 |
| size | 15,971 |

gltf-v1-derive provides procedural macro support for glTF 1.0 validation and serialization. This crate is part of the asset-importer-rs project and provides the necessary derive macros for implementing validation and serialization traits, enabling automatic code generation for glTF 1.0 data structures.
This crate provides the essential functionality for:



Add the following to your Cargo.toml:
[dependencies]
gltf-v1-derive = "0.3.0"
# Or for development from source:
gltf-v1-derive = { path = "../path/to/gltf-v1-derive" }

Basic validation derive example:
use gltf_v1_derive::Validate;
#[derive(Validate)]
struct MyStruct {
field1: String,
field2: i32,
}
// The Validate trait is automatically implemented
let my_struct = MyStruct {
field1: "test".to_string(),
field2: 42,
};
// Validation can be called automatically
my_struct.validate(&root, &path, &mut report)?;
Custom validation hook example:
use gltf_v1_derive::Validate;
#[derive(Validate)]
#[gltf(validate_hook = "custom_validate")]
struct CustomStruct {
field1: String,
field2: i32,
}
fn custom_validate(
this: &CustomStruct,
root: &Root,
path: impl Fn() -> Path,
report: &mut impl FnMut(&dyn Fn() -> Path, Error),
) {
// Custom validation logic
if this.field2 < 0 {
report(&path, Error::InvalidValue("field2 must be positive"));
}
}
Nested structure validation:
use gltf_v1_derive::Validate;
#[derive(Validate)]
struct ParentStruct {
child: ChildStruct,
name: String,
}
#[derive(Validate)]
struct ChildStruct {
value: f32,
#[gltf(validate_hook = "validate_range")]
range: i32,
}
fn validate_range(
this: &i32,
_root: &Root,
path: impl Fn() -> Path,
report: &mut impl FnMut(&dyn Fn() -> Path, Error),
) {
if *this < 0 || *this > 100 {
report(&path, Error::InvalidValue("range must be between 0 and 100"));
}
}

The crate provides comprehensive procedural macro support for glTF 1.0 validation and serialization, enabling automatic code generation and trait implementation.


This crate is primarily intended for internal use within the asset-importer-rs project, specifically for the glTF 1.0 implementation. It provides the necessary derive macros for implementing validation and serialization traits that are used throughout the glTF 1.0 ecosystem.
While the crate can be used independently, it is designed and optimized for use within the asset-importer-rs workspace and may have dependencies on internal types and traits specific to the project.

This project is part of the asset-importer-rs workspace and follows its licensing terms. See the main project LICENSE file for details.
Copyright (c) 2024 Jackson Levitt