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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: Copyright (c) 2025 Asymptotic Inc.
// SPDX-FileCopyrightText: Copyright (c) 2025 Arun Raghavan
use bitflags::bitflags;
use crate::Id;
bitflags! {
/// Represents permissions within PipeWire.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PermissionBits : u32 {
/// Object can be read and events received.
const READ = (1 << 8);
/// Alias for [`Self::READ`]
const R = (1 << 8);
/// Methods that modify the object can be called.
const WRITE = (1 << 7);
/// Alias for [`Self::WRITE`]
const W = (1 << 7);
/// Methods can be called on the object.
const EXECUTE = (1 << 6);
/// Alias for [`Self::EXECUTE`]
const X = (1 << 6);
/// Metadata can be set on the object.
const METADATA = (1 << 3);
/// Alias for [`Self::METADATA`]
const M = (1 << 3);
/// A link can be made between a node that doesn't have permission to see another node.
const LINK = (1 << 4);
/// Alias for [`Self::LINK`]
const L = (1 << 4);
}
}
/// Represents permissions on an object.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Permission {
/// The object on which the permissions apply.
pub id: Id,
/// The permissions of the object.
pub permissions: PermissionBits,
}
impl std::fmt::Display for PermissionBits {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.contains(PermissionBits::READ) {
write!(f, "r")
} else {
write!(f, "-")
}?;
if self.contains(PermissionBits::WRITE) {
write!(f, "w")
} else {
write!(f, "-")
}?;
if self.contains(PermissionBits::EXECUTE) {
write!(f, "x")
} else {
write!(f, "-")
}?;
if self.contains(PermissionBits::METADATA) {
write!(f, "m")
} else {
write!(f, "-")
}?;
if self.contains(PermissionBits::LINK) {
write!(f, "l")
} else {
write!(f, "-")
}
}
}