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
53
54
55
56
57
58
use super::{containers_from_repr_c, containers_into_vec, AppExchangeInfo, ContainerPermissions};
use ffi::ipc::req as ffi;
use ffi_utils::{vec_into_raw_parts, ReprC, StringError};
use ipc::errors::IpcError;
use std::collections::HashMap;
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug)]
pub struct ContainersReq {
pub app: AppExchangeInfo,
pub containers: HashMap<String, ContainerPermissions>,
}
impl ContainersReq {
pub fn into_repr_c(self) -> Result<ffi::ContainersReq, IpcError> {
let ContainersReq { app, containers } = self;
let containers = containers_into_vec(containers).map_err(StringError::from)?;
let (containers_ptr, containers_len, containers_cap) = vec_into_raw_parts(containers);
Ok(ffi::ContainersReq {
app: app.into_repr_c()?,
containers: containers_ptr,
containers_len,
containers_cap,
})
}
}
impl ReprC for ContainersReq {
type C = *const ffi::ContainersReq;
type Error = IpcError;
unsafe fn clone_from_repr_c(repr_c: *const ffi::ContainersReq) -> Result<Self, IpcError> {
Ok(ContainersReq {
app: AppExchangeInfo::clone_from_repr_c(&(*repr_c).app)?,
containers: containers_from_repr_c((*repr_c).containers, (*repr_c).containers_len)?,
})
}
}