Nothing to see here, move along meow
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 3.2 kB View raw
1use crate::object_tag::ObjectTag; 2use crate::types::{Generation, ObjPhys}; 3 4#[derive(Debug, Clone, Copy, PartialEq, Eq)] 5pub struct Rights(u16); 6 7impl Rights { 8 #[allow(dead_code)] 9 pub const NONE: Self = Self(0); 10 pub const READ: Self = Self(1 << 0); 11 pub const WRITE: Self = Self(1 << 1); 12 pub const GRANT: Self = Self(1 << 2); 13 pub const REVOKE: Self = Self(1 << 3); 14 pub const ALL: Self = Self(0b1111); 15 16 pub const fn bits(self) -> u16 { 17 self.0 18 } 19 20 pub const fn contains(self, other: Self) -> bool { 21 (self.0 & other.0) == other.0 22 } 23 24 pub const fn from_bits(bits: u16) -> Self { 25 Self(bits & Self::ALL.0) 26 } 27} 28 29impl core::ops::BitOr for Rights { 30 type Output = Self; 31 fn bitor(self, rhs: Self) -> Self { 32 Self(self.0 | rhs.0) 33 } 34} 35 36impl core::ops::BitAnd for Rights { 37 type Output = Self; 38 fn bitand(self, rhs: Self) -> Self { 39 Self(self.0 & rhs.0) 40 } 41} 42 43impl core::ops::Not for Rights { 44 type Output = Self; 45 fn not(self) -> Self { 46 Self(!self.0 & Self::ALL.0) 47 } 48} 49 50impl core::ops::BitOrAssign for Rights { 51 fn bitor_assign(&mut self, rhs: Self) { 52 self.0 |= rhs.0; 53 } 54} 55 56impl core::ops::BitAndAssign for Rights { 57 fn bitand_assign(&mut self, rhs: Self) { 58 self.0 &= rhs.0; 59 } 60} 61 62#[derive(Debug, Clone, Copy, PartialEq, Eq)] 63pub struct CapRef { 64 tag: ObjectTag, 65 phys: ObjPhys, 66 rights: Rights, 67 generation: Generation, 68 guard_value: u64, 69 guard_bits: u8, 70} 71 72impl CapRef { 73 pub const fn new( 74 tag: ObjectTag, 75 phys: ObjPhys, 76 rights: Rights, 77 generation: Generation, 78 ) -> Self { 79 Self { 80 tag, 81 phys, 82 rights, 83 generation, 84 guard_value: 0, 85 guard_bits: 0, 86 } 87 } 88 89 pub const fn new_with_guard( 90 tag: ObjectTag, 91 phys: ObjPhys, 92 rights: Rights, 93 generation: Generation, 94 guard_value: u64, 95 guard_bits: u8, 96 ) -> Self { 97 Self { 98 tag, 99 phys, 100 rights, 101 generation, 102 guard_value, 103 guard_bits, 104 } 105 } 106 107 pub const fn tag(&self) -> ObjectTag { 108 self.tag 109 } 110 111 pub const fn phys(&self) -> ObjPhys { 112 self.phys 113 } 114 115 pub const fn rights(&self) -> Rights { 116 self.rights 117 } 118 119 pub const fn generation(&self) -> Generation { 120 self.generation 121 } 122 123 pub const fn guard_value(&self) -> u64 { 124 self.guard_value 125 } 126 127 pub const fn guard_bits(&self) -> u8 { 128 self.guard_bits 129 } 130 131 pub const fn with_rights(self, rights: Rights) -> Self { 132 Self { rights, ..self } 133 } 134 135 pub const fn with_guard(self, guard_value: u64, guard_bits: u8) -> Self { 136 Self { 137 guard_value, 138 guard_bits, 139 ..self 140 } 141 } 142} 143 144#[derive(Debug, Clone, Copy, PartialEq, Eq)] 145pub enum CapSlot { 146 Empty, 147 Active(CapRef), 148} 149 150impl CapSlot { 151 pub const fn is_empty(&self) -> bool { 152 match self { 153 Self::Empty => true, 154 Self::Active(_) => false, 155 } 156 } 157}