Skip to main content

hyprstream_rpc/auth/
scope_registry.rs

1//! Compile-time scope registration via inventory pattern.
2//!
3//! Services can register scopes at compile time using inventory::submit!
4//! This ensures all scopes are discoverable and documented.
5
6/// Scope definition for compile-time registration.
7pub struct ScopeDefinition {
8    pub action: &'static str,
9    pub resource: &'static str,
10    pub example: &'static str,
11    pub description: &'static str,
12}
13
14impl ScopeDefinition {
15    pub const fn new(
16        action: &'static str,
17        resource: &'static str,
18        example: &'static str,
19        description: &'static str,
20    ) -> Self {
21        Self {
22            action,
23            resource,
24            example,
25            description,
26        }
27    }
28}
29
30// Collect all registered scopes.
31//
32// Native-only (#1305): inventory's link-time registration doesn't resolve on
33// wasm32. The browser client has no scope-registry consumer, so no wasm
34// fallback is needed — the collection and its iterator are compiled out.
35#[cfg(not(target_arch = "wasm32"))]
36inventory::collect!(ScopeDefinition);
37
38/// Get all registered scopes.
39#[cfg(not(target_arch = "wasm32"))]
40pub fn registered_scopes() -> impl Iterator<Item = &'static ScopeDefinition> {
41    inventory::iter::<ScopeDefinition>()
42}