#[derive(Debug, Clone, Copy, Default)]
pub struct CommandDescriptor {
flags: u16,
}
impl CommandDescriptor {
const FLAG_PROFILE: u16 = 0b0000_0000_0001;
const FLAG_SECRETS: u16 = 0b0000_0000_0010;
const FLAG_PATHS: u16 = 0b0000_0000_0100;
const FLAG_DATABASE: u16 = 0b0000_0000_1000;
const FLAG_REMOTE_ELIGIBLE: u16 = 0b0000_0001_0000;
const FLAG_SKIP_VALIDATION: u16 = 0b0000_0010_0000;
const FLAG_READ_ONLY: u16 = 0b0000_0100_0000;
const FLAG_MODEL_DISCOVERY: u16 = 0b0000_1000_0000;
const FLAG_EXPLICIT_CLOUD_PROFILE: u16 = 0b0001_0000_0000;
pub const NONE: Self = Self { flags: 0 };
pub const PROFILE_ONLY: Self = Self {
flags: Self::FLAG_PROFILE,
};
pub const PROFILE_AND_SECRETS: Self = Self {
flags: Self::FLAG_PROFILE | Self::FLAG_SECRETS,
};
pub const PROFILE_SECRETS_AND_PATHS: Self = Self {
flags: Self::FLAG_PROFILE | Self::FLAG_SECRETS | Self::FLAG_PATHS,
};
pub const FULL: Self = Self {
flags: Self::FLAG_PROFILE
| Self::FLAG_SECRETS
| Self::FLAG_PATHS
| Self::FLAG_DATABASE
| Self::FLAG_REMOTE_ELIGIBLE,
};
pub const fn profile(&self) -> bool {
self.flags & Self::FLAG_PROFILE != 0
}
pub const fn secrets(&self) -> bool {
self.flags & Self::FLAG_SECRETS != 0
}
pub const fn paths(&self) -> bool {
self.flags & Self::FLAG_PATHS != 0
}
pub const fn database(&self) -> bool {
self.flags & Self::FLAG_DATABASE != 0
}
pub const fn routing_class(&self) -> RoutingClass {
if self.flags & Self::FLAG_REMOTE_ELIGIBLE == 0 {
RoutingClass::LocalOnly
} else if self.flags & Self::FLAG_READ_ONLY != 0 {
RoutingClass::ReadOnly
} else {
RoutingClass::Mutating
}
}
pub const fn skip_validation(&self) -> bool {
self.flags & Self::FLAG_SKIP_VALIDATION != 0
}
pub const fn discovers_models(&self) -> bool {
self.flags & Self::FLAG_MODEL_DISCOVERY != 0
}
pub const fn with_remote_eligible(self) -> Self {
Self {
flags: self.flags | Self::FLAG_REMOTE_ELIGIBLE,
}
}
pub const fn with_read_only(self) -> Self {
Self {
flags: self.flags | Self::FLAG_READ_ONLY,
}
}
pub const fn with_skip_validation(self) -> Self {
Self {
flags: self.flags | Self::FLAG_SKIP_VALIDATION,
}
}
pub const fn with_model_discovery(self) -> Self {
Self {
flags: self.flags | Self::FLAG_MODEL_DISCOVERY,
}
}
pub const fn requires_explicit_cloud_profile(&self) -> bool {
self.flags & Self::FLAG_EXPLICIT_CLOUD_PROFILE != 0
}
pub const fn with_explicit_cloud_profile(self) -> Self {
Self {
flags: self.flags | Self::FLAG_EXPLICIT_CLOUD_PROFILE,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RoutingClass {
LocalOnly,
ReadOnly,
Mutating,
}
pub trait DescribeCommand {
fn descriptor(&self) -> CommandDescriptor;
}