aranya_client/client/
role.rs1use std::{slice, vec};
2
3use aranya_daemon_api as api;
4use aranya_id::custom_id;
5use aranya_policy_text::Text;
6
7use crate::{
8 client::DeviceId,
9 util::{impl_slice_iter_wrapper, impl_vec_into_iter_wrapper, ApiConv as _, ApiId},
10};
11
12custom_id! {
13 pub struct RoleId;
15}
16impl ApiId<api::RoleId> for RoleId {}
17
18#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
20#[non_exhaustive]
21pub struct Role {
22 pub id: RoleId,
24 pub name: Text,
26 pub author_id: DeviceId,
28 pub default: bool,
30}
31
32impl Role {
33 pub(crate) fn from_api(v: api::Role) -> Self {
34 Self {
35 id: RoleId::from_api(v.id),
36 name: v.name,
37 author_id: DeviceId::from_api(v.author_id),
38 default: v.default,
39 }
40 }
41}
42
43#[derive(Clone, Debug)]
45pub struct Roles {
46 pub(super) roles: Box<[Role]>,
47}
48
49impl Roles {
50 pub fn iter(&self) -> IterRoles<'_> {
52 IterRoles(self.roles.iter())
53 }
54
55 #[doc(hidden)]
56 pub fn __into_data(self) -> Box<[Role]> {
57 self.roles
58 }
59}
60
61impl IntoIterator for Roles {
62 type Item = Role;
63 type IntoIter = IntoIterRoles;
64
65 fn into_iter(self) -> Self::IntoIter {
66 IntoIterRoles(self.roles.into_vec().into_iter())
67 }
68}
69
70#[derive(Clone, Debug)]
72pub struct IterRoles<'a>(slice::Iter<'a, Role>);
73
74impl_slice_iter_wrapper!(IterRoles<'a> for Role);
75
76#[derive(Clone, Debug)]
78pub struct IntoIterRoles(vec::IntoIter<Role>);
79
80impl_vec_into_iter_wrapper!(IntoIterRoles for Role);