spiral-sdk 0.1.11

Rust SDK for Spiral resource and table APIs
Documentation
//! Stable identifiers used by control-plane management operations.

use std::fmt::{Display, Formatter, Result as FmtResult};

use serde::{Deserialize, Serialize};

/// A Project authorization grant identifier.
pub type GrantId = String;

macro_rules! string_id {
    ($($(#[$doc:meta])* $name:ident;)*) => {$(
        $(#[$doc])*
        #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
        #[serde(transparent)]
        pub struct $name(String);

        impl $name {
            /// The identifier as the API spells it.
            pub fn as_str(&self) -> &str {
                &self.0
            }
        }

        impl From<String> for $name {
            fn from(id: String) -> Self {
                Self(id)
            }
        }

        impl From<&str> for $name {
            fn from(id: &str) -> Self {
                Self(id.to_owned())
            }
        }

        impl AsRef<str> for $name {
            fn as_ref(&self) -> &str {
                &self.0
            }
        }

        impl Display for $name {
            fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
                f.write_str(&self.0)
            }
        }
    )*};
}

string_id! {
    /// An OAuth client: an application, a workload or an installation.
    ClientId;
    /// An organization.
    OrgId;
    /// A project.
    ProjectId;
    /// A user.
    UserId;
    /// A workload: a non-human identity that runs jobs in a project.
    WorkloadId;
}