pub struct ModuleAccessFlags(/* private fields */);Expand description
Module access flags used in Java class files.
The ModuleAccessFlags type represents the access flags in the Module attribute of a Java
class file.
§Examples
use ristretto_classfile::byte_reader::ByteReader;
use ristretto_classfile::attributes::ModuleAccessFlags;
// Create flags using individual constants
let flags = ModuleAccessFlags::OPEN | ModuleAccessFlags::SYNTHETIC;
// Test for specific flags
assert!(flags.contains(ModuleAccessFlags::OPEN));
assert!(flags.contains(ModuleAccessFlags::SYNTHETIC));
assert!(!flags.contains(ModuleAccessFlags::MANDATED));
// Convert to string representation
assert_eq!(flags.to_string(), "(0x1020) ACC_OPEN, ACC_SYNTHETIC");
// Serialize to bytes
let mut bytes = Vec::new();
flags.to_bytes(&mut bytes)?;
assert_eq!(bytes, vec![0x10, 0x20]);
// Deserialize from bytes
let mut reader = ByteReader::new(&bytes);
let deserialized = ModuleAccessFlags::from_bytes(&mut reader)?;
assert_eq!(deserialized, flags);§References
Implementations§
Source§impl ModuleAccessFlags
impl ModuleAccessFlags
Sourcepub const fn bits(&self) -> u16
pub const fn bits(&self) -> u16
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: u16) -> Option<Self>
pub const fn from_bits(bits: u16) -> Option<Self>
Convert from a bits value.
This method will return None if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: u16) -> Self
pub const fn from_bits_truncate(bits: u16) -> Self
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: u16) -> Self
pub const fn from_bits_retain(bits: u16) -> Self
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Get a flags value with the bits of a flag with the given name set.
This method will return None if name is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Whether any set bits in other are also set in self.
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether all set bits in other are also set in self.
Sourcepub fn remove(&mut self, other: Self)
pub fn remove(&mut self, other: Self)
The intersection of self with the complement of other (&!).
This method is not equivalent to self & !other when other has unknown bits set.
remove won’t truncate other, but the ! operator will.
Sourcepub fn toggle(&mut self, other: Self)
pub fn toggle(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in self and other.
Sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Call insert when value is true or remove when value is false.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
The bitwise and (&) of the bits in self and other.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The bitwise or (|) of the bits in self and other.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
The intersection of self with the complement of other (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
The bitwise exclusive-or (^) of the bits in self and other.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The bitwise negation (!) of the bits in self, truncating the result.
Source§impl ModuleAccessFlags
impl ModuleAccessFlags
Sourcepub const fn iter(&self) -> Iter<ModuleAccessFlags>
pub const fn iter(&self) -> Iter<ModuleAccessFlags>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<ModuleAccessFlags>
pub const fn iter_names(&self) -> IterNames<ModuleAccessFlags>
Yield a set of contained named flags values.
This method is like iter, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Source§impl ModuleAccessFlags
impl ModuleAccessFlags
Sourcepub fn from_bytes(bytes: &mut ByteReader<'_>) -> Result<ModuleAccessFlags>
pub fn from_bytes(bytes: &mut ByteReader<'_>) -> Result<ModuleAccessFlags>
Deserialize the ModuleAccessFlags from bytes.
§Errors
Should not occur; reserved for future use.
§Examples
use ristretto_classfile::byte_reader::ByteReader;
use ristretto_classfile::attributes::ModuleAccessFlags;
let mut bytes = ByteReader::new(&[0x00, 0x20]); // ACC_OPEN
let flags = ModuleAccessFlags::from_bytes(&mut bytes)?;
assert_eq!(flags, ModuleAccessFlags::OPEN);Sourcepub fn to_bytes(&self, bytes: &mut Vec<u8>) -> Result<()>
pub fn to_bytes(&self, bytes: &mut Vec<u8>) -> Result<()>
Serialize the ModuleAccessFlags to bytes.
§Errors
Should not occur; reserved for future use.
§Examples
use ristretto_classfile::attributes::ModuleAccessFlags;
let flags = ModuleAccessFlags::OPEN | ModuleAccessFlags::SYNTHETIC;
let mut bytes = Vec::new();
flags.to_bytes(&mut bytes)?;
assert_eq!(bytes, vec![0x10, 0x20]); // 0x0020 | 0x1000Trait Implementations§
Source§impl Binary for ModuleAccessFlags
impl Binary for ModuleAccessFlags
Source§impl BitAnd for ModuleAccessFlags
impl BitAnd for ModuleAccessFlags
Source§impl BitAndAssign for ModuleAccessFlags
impl BitAndAssign for ModuleAccessFlags
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
The bitwise and (&) of the bits in self and other.
Source§impl BitOr for ModuleAccessFlags
impl BitOr for ModuleAccessFlags
Source§fn bitor(self, other: ModuleAccessFlags) -> Self
fn bitor(self, other: ModuleAccessFlags) -> Self
The bitwise or (|) of the bits in self and other.
Source§type Output = ModuleAccessFlags
type Output = ModuleAccessFlags
| operator.Source§impl BitOrAssign for ModuleAccessFlags
impl BitOrAssign for ModuleAccessFlags
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
The bitwise or (|) of the bits in self and other.
Source§impl BitXor for ModuleAccessFlags
impl BitXor for ModuleAccessFlags
Source§impl BitXorAssign for ModuleAccessFlags
impl BitXorAssign for ModuleAccessFlags
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in self and other.
Source§impl Clone for ModuleAccessFlags
impl Clone for ModuleAccessFlags
Source§fn clone(&self) -> ModuleAccessFlags
fn clone(&self) -> ModuleAccessFlags
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ModuleAccessFlags
Source§impl Debug for ModuleAccessFlags
impl Debug for ModuleAccessFlags
Source§impl Default for ModuleAccessFlags
impl Default for ModuleAccessFlags
Source§fn default() -> ModuleAccessFlags
fn default() -> ModuleAccessFlags
Source§impl Display for ModuleAccessFlags
impl Display for ModuleAccessFlags
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Implements the Display trait for ModuleAccessFlags, allowing flags to be printed in a human-readable format.
The output format consists of:
- The hexadecimal value of the flags in parentheses (e.g., “(0x0020)”)
- A list of named flags separated by commas (e.g., “
ACC_OPEN, ACC_SYNTHETIC”)
§Examples
use ristretto_classfile::attributes::ModuleAccessFlags;
let flags = ModuleAccessFlags::OPEN | ModuleAccessFlags::SYNTHETIC;
let output = flags.to_string();
assert_eq!(output, "(0x1020) ACC_OPEN, ACC_SYNTHETIC");
let empty = ModuleAccessFlags::empty();
assert_eq!(empty.to_string(), "(0x0000) ");impl Eq for ModuleAccessFlags
Source§impl Extend<ModuleAccessFlags> for ModuleAccessFlags
impl Extend<ModuleAccessFlags> for ModuleAccessFlags
Source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
The bitwise or (|) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Flags for ModuleAccessFlags
impl Flags for ModuleAccessFlags
Source§const FLAGS: &'static [Flag<ModuleAccessFlags>]
const FLAGS: &'static [Flag<ModuleAccessFlags>]
Source§fn from_bits_retain(bits: u16) -> ModuleAccessFlags
fn from_bits_retain(bits: u16) -> ModuleAccessFlags
Source§fn all_named() -> ModuleAccessFlags
fn all_named() -> ModuleAccessFlags
Source§fn known_bits(&self) -> Self::Bits
fn known_bits(&self) -> Self::Bits
Source§fn unknown_bits(&self) -> Self::Bits
fn unknown_bits(&self) -> Self::Bits
Source§fn contains_unknown_bits(&self) -> bool
fn contains_unknown_bits(&self) -> bool
true if any unknown bits are set.Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn iter_defined_names() -> IterDefinedNames<Self>
fn iter_defined_names() -> IterDefinedNames<Self>
Self::FLAGS.Source§fn iter_equal_names(&self) -> IterEqualNames<Self>
fn iter_equal_names(&self) -> IterEqualNames<Self>
Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
other are also set in self.Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
other are also set in self.Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|) of the bits in self and other.Source§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^) of the bits in self and other.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&) of the bits in self and other.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
Source§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^) of the bits in self and other.Source§fn complement(self) -> Self
fn complement(self) -> Self
!) of the bits in self, truncating the result.Source§impl FromIterator<ModuleAccessFlags> for ModuleAccessFlags
impl FromIterator<ModuleAccessFlags> for ModuleAccessFlags
Source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
The bitwise or (|) of the bits in each flags value.
Source§impl IntoIterator for ModuleAccessFlags
impl IntoIterator for ModuleAccessFlags
Source§impl LowerHex for ModuleAccessFlags
impl LowerHex for ModuleAccessFlags
Source§impl Not for ModuleAccessFlags
impl Not for ModuleAccessFlags
Source§impl Octal for ModuleAccessFlags
impl Octal for ModuleAccessFlags
Source§impl PartialEq for ModuleAccessFlags
impl PartialEq for ModuleAccessFlags
Source§impl PublicFlags for ModuleAccessFlags
impl PublicFlags for ModuleAccessFlags
impl StructuralPartialEq for ModuleAccessFlags
Source§impl Sub for ModuleAccessFlags
impl Sub for ModuleAccessFlags
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
The intersection of self with the complement of other (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Source§type Output = ModuleAccessFlags
type Output = ModuleAccessFlags
- operator.Source§impl SubAssign for ModuleAccessFlags
impl SubAssign for ModuleAccessFlags
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
The intersection of self with the complement of other (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Auto Trait Implementations§
impl Freeze for ModuleAccessFlags
impl RefUnwindSafe for ModuleAccessFlags
impl Send for ModuleAccessFlags
impl Sync for ModuleAccessFlags
impl Unpin for ModuleAccessFlags
impl UnsafeUnpin for ModuleAccessFlags
impl UnwindSafe for ModuleAccessFlags
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.