1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Embedded `SpiceDB` using CGO FFI with native gRPC.
//!
//! This crate provides an in-process `SpiceDB` instance for authorization checks.
//! It uses a C-shared library to start `SpiceDB` servers, then connects via Unix
//! socket. All API access is through tonic clients generated from
//! [buf.build/authzed/api](https://buf.build/authzed/api) (see the `spicedb-grpc-tonic` crate).
//!
//! # Example
//!
//! ```ignore
//! use spicedb_embedded::{v1, EmbeddedSpiceDB};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let schema = r#"
//! definition user {}
//! definition document {
//! relation reader: user
//! permission read = reader
//! }
//! "#;
//!
//! let relationships = vec![v1::Relationship {
//! resource: Some(v1::ObjectReference { object_type: "document".into(), object_id: "readme".into() }),
//! relation: "reader".into(),
//! subject: Some(v1::SubjectReference {
//! object: Some(v1::ObjectReference { object_type: "user".into(), object_id: "alice".into() }),
//! optional_relation: String::new(),
//! }),
//! optional_caveat: None,
//! }];
//!
//! let spicedb = EmbeddedSpiceDB::start_with_schema(schema, &relationships, None)?;
//! let mut permissions = spicedb.permissions();
//! // Use the full SpiceDB API via the generated client
//! let response = permissions.check_permission(&v1::CheckPermissionRequest {
//! consistency: None,
//! resource: Some(v1::ObjectReference { object_type: "document".into(), object_id: "readme".into() }),
//! permission: "read".into(),
//! subject: Some(v1::SubjectReference {
//! object: Some(v1::ObjectReference { object_type: "user".into(), object_id: "alice".into() }),
//! optional_relation: String::new(),
//! }),
//! context: None,
//! with_tracing: false,
//! })?;
//! Ok(())
//! }
//! ```
pub use ;
// Re-export spicedb-grpc so users have direct access to all generated types
pub use v1;
/// Errors from embedded `SpiceDB` operations