use bitflags::bitflags;
use oxc_index::define_index_type;
#[cfg(feature = "serde")]
use serde::Serialize;
define_index_type! {
pub struct ReferenceId = u32;
}
bitflags! {
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct ReferenceFlag: u8 {
const None = 0;
const Read = 1 << 0;
const Write = 1 << 1;
const ReadWrite = Self::Read.bits() | Self::Write.bits();
}
}
impl ReferenceFlag {
pub const fn read() -> Self {
Self::Read
}
pub const fn write() -> Self {
Self::Write
}
pub const fn read_write() -> Self {
Self::ReadWrite
}
pub const fn is_read(&self) -> bool {
self.intersects(Self::Read)
}
pub const fn is_read_only(&self) -> bool {
self.contains(Self::Read)
}
pub const fn is_write(&self) -> bool {
self.intersects(Self::Write)
}
pub const fn is_write_only(&self) -> bool {
self.contains(Self::Write)
}
pub const fn is_read_write(&self) -> bool {
self.contains(Self::ReadWrite)
}
}