#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Supports {
pub cancel_execution: bool,
pub change_priority: bool,
pub replay_execution: bool,
pub revoke_lease: bool,
pub read_execution_state: bool,
pub read_execution_info: bool,
pub get_execution_result: bool,
pub budget_admin: bool,
pub quota_admin: bool,
pub rotate_waitpoint_hmac_secret_all: bool,
pub seed_waitpoint_hmac_secret: bool,
pub list_pending_waitpoints: bool,
pub cancel_flow_header: bool,
pub cancel_flow_wait_timeout: bool,
pub cancel_flow_wait_indefinite: bool,
pub ack_cancel_member: bool,
pub claim_for_worker: bool,
pub prepare: bool,
pub subscribe_lease_history: bool,
pub subscribe_completion: bool,
pub subscribe_signal_delivery: bool,
pub subscribe_instance_tags: bool,
pub stream_durable_summary: bool,
pub stream_best_effort_live: bool,
}
impl Supports {
pub const fn none() -> Self {
Self {
cancel_execution: false,
change_priority: false,
replay_execution: false,
revoke_lease: false,
read_execution_state: false,
read_execution_info: false,
get_execution_result: false,
budget_admin: false,
quota_admin: false,
rotate_waitpoint_hmac_secret_all: false,
seed_waitpoint_hmac_secret: false,
list_pending_waitpoints: false,
cancel_flow_header: false,
cancel_flow_wait_timeout: false,
cancel_flow_wait_indefinite: false,
ack_cancel_member: false,
claim_for_worker: false,
prepare: false,
subscribe_lease_history: false,
subscribe_completion: false,
subscribe_signal_delivery: false,
subscribe_instance_tags: false,
stream_durable_summary: false,
stream_best_effort_live: false,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Version {
pub major: u32,
pub minor: u32,
pub patch: u32,
}
impl Version {
pub const fn new(major: u32, minor: u32, patch: u32) -> Self {
Self {
major,
minor,
patch,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BackendIdentity {
pub family: &'static str,
pub version: Version,
pub rfc017_stage: &'static str,
}
impl BackendIdentity {
pub const fn new(
family: &'static str,
version: Version,
rfc017_stage: &'static str,
) -> Self {
Self {
family,
version,
rfc017_stage,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Capabilities {
pub identity: BackendIdentity,
pub supports: Supports,
}
impl Capabilities {
pub const fn new(identity: BackendIdentity, supports: Supports) -> Self {
Self { identity, supports }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn version_new_is_const_and_ordered() {
const V: Version = Version::new(0, 9, 0);
assert_eq!(V.major, 0);
assert_eq!(V.minor, 9);
assert_eq!(V.patch, 0);
assert!(Version::new(0, 10, 0) > V);
assert!(Version::new(0, 9, 1) > V);
assert!(Version::new(1, 0, 0) > V);
}
#[test]
fn backend_identity_new_populates_fields() {
let id = BackendIdentity::new("valkey", Version::new(0, 9, 0), "E-shipped");
assert_eq!(id.family, "valkey");
assert_eq!(id.version, Version::new(0, 9, 0));
assert_eq!(id.rfc017_stage, "E-shipped");
}
#[test]
fn supports_none_is_all_false() {
let s = Supports::none();
assert!(!s.cancel_execution);
assert!(!s.budget_admin);
assert!(!s.quota_admin);
assert!(!s.subscribe_instance_tags);
assert!(!s.stream_durable_summary);
assert_eq!(s, Supports::default());
}
#[test]
fn capabilities_new_wires_identity_and_supports() {
let mut s = Supports::none();
s.cancel_execution = true;
let caps = Capabilities::new(
BackendIdentity::new("valkey", Version::new(0, 10, 0), "E-shipped"),
s,
);
assert_eq!(caps.identity.family, "valkey");
assert!(caps.supports.cancel_execution);
assert!(!caps.supports.change_priority);
}
}