Crate inferadb_derive

Crate inferadb_derive 

Source
Expand description

Derive macros for the InferaDB SDK.

This crate provides derive macros for implementing the Resource and Subject traits, enabling type-safe authorization operations.

§Usage

Add to your Cargo.toml:

[dependencies]
inferadb = { version = "0.1", features = ["derive"] }

§Examples

use inferadb::derive::{Resource, Subject};

#[derive(Resource)]
#[resource(type = "document")]
struct Document {
    #[resource(id)]
    id: String,
    title: String,
}

#[derive(Subject)]
#[subject(type = "user")]
struct User {
    #[subject(id)]
    id: String,
    name: String,
}

// Now you can use these with the InferaDB SDK
let doc = Document { id: "readme".into(), title: "README".into() };
let user = User { id: "alice".into(), name: "Alice".into() };

// Type-safe API
assert_eq!(doc.as_resource_ref(), "document:readme");
assert_eq!(user.as_subject_ref(), "user:alice");

Derive Macros§

Resource
Derive macro for implementing the Resource trait.
Subject
Derive macro for implementing the Subject trait.