zvariant/serialized/
written.rs1#[cfg(unix)]
2use crate::OwnedFd;
3use std::ops::Deref;
4
5use crate::serialized::Context;
6
7#[derive(Debug)]
14pub struct Written {
15 size: usize,
16 context: Context,
17 #[cfg(unix)]
18 fds: Vec<OwnedFd>,
19}
20
21impl Written {
22 pub fn new(size: usize, context: Context) -> Self {
24 Self {
25 size,
26 context,
27 #[cfg(unix)]
28 fds: vec![],
29 }
30 }
31
32 #[cfg(unix)]
34 pub fn set_fds(mut self, fds: impl IntoIterator<Item = impl Into<OwnedFd>>) -> Self {
35 self.fds = fds.into_iter().map(Into::into).collect();
36 self
37 }
38
39 pub fn size(&self) -> usize {
41 self.size
42 }
43
44 pub fn context(&self) -> Context {
46 self.context
47 }
48
49 #[cfg(unix)]
53 pub fn into_fds(self) -> Vec<OwnedFd> {
54 self.fds
55 }
56
57 #[cfg(unix)]
61 pub fn fds(&self) -> &[OwnedFd] {
62 &self.fds
63 }
64}
65
66impl Deref for Written {
67 type Target = usize;
68
69 fn deref(&self) -> &Self::Target {
70 &self.size
71 }
72}