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
use crate::ffi::mutable_data::permissions::UserPermissionSet as FfiUserPermissionSet;
use crate::ffi::object_cache::SignPubKeyHandle;
use ffi_utils::ReprC;
use safe_core::ipc::req::{permission_set_clone_from_repr_c, permission_set_into_repr_c};
use safe_core::ipc::IpcError;
use safe_nd::MDataPermissionSet;
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct UserPermissionSet {
pub user_h: SignPubKeyHandle,
pub perm_set: MDataPermissionSet,
}
impl UserPermissionSet {
pub fn into_repr_c(self) -> FfiUserPermissionSet {
FfiUserPermissionSet {
user_h: self.user_h,
perm_set: permission_set_into_repr_c(self.perm_set),
}
}
}
impl ReprC for UserPermissionSet {
type C = *const FfiUserPermissionSet;
type Error = IpcError;
#[allow(unsafe_code)]
unsafe fn clone_from_repr_c(repr_c: Self::C) -> Result<Self, Self::Error> {
let FfiUserPermissionSet { user_h, perm_set } = *repr_c;
Ok(Self {
user_h,
perm_set: permission_set_clone_from_repr_c(perm_set)?,
})
}
}