1use crate::UserId;
2use std::fmt::{Display, Formatter};
3use tonic::Status;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub struct Principal(UserId);
8
9impl Principal {
10 pub fn user_id(&self) -> UserId {
11 self.0
12 }
13}
14
15impl From<UserId> for Principal {
16 fn from(value: UserId) -> Self {
17 Principal(value)
18 }
19}
20
21impl Display for Principal {
22 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23 self.0.fmt(f)
24 }
25}
26
27#[derive(Clone, Debug)]
28pub enum CheckResult {
29 Ok(Principal),
30 Forbidden(Principal),
31}
32
33impl CheckResult {
34 pub fn is_ok(&self) -> bool {
36 matches!(self, CheckResult::Ok(_))
37 }
38}
39
40#[derive(thiserror::Error, Debug)]
41pub enum CallError {
42 #[error("unexpected response format")]
43 UnexpectedResponseFormat,
44 #[error("call error: {0}")]
45 Status(#[from] Status),
46}