use facet::{Facet, Shape};
pub struct ServiceDescriptor {
pub service_name: &'static str,
pub methods: &'static [&'static MethodDescriptor],
pub doc: Option<&'static str>,
}
impl ServiceDescriptor {
pub fn by_id(&self, method_id: MethodId) -> Option<&'static MethodDescriptor> {
self.methods.iter().find(|m| m.id == method_id).copied()
}
}
pub struct MethodDescriptor {
pub id: MethodId,
pub service_name: &'static str,
pub method_name: &'static str,
pub args_shape: &'static Shape,
pub args: &'static [ArgDescriptor],
pub return_shape: &'static Shape,
pub retry: RetryPolicy,
pub doc: Option<&'static str>,
}
impl std::fmt::Debug for MethodDescriptor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MethodDescriptor")
.field("id", &self.id)
.field("service_name", &self.service_name)
.field("method_name", &self.method_name)
.field("retry", &self.retry)
.finish_non_exhaustive()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct RetryPolicy {
pub persist: bool,
pub idem: bool,
}
impl RetryPolicy {
pub const VOLATILE: Self = Self {
persist: false,
idem: false,
};
pub const IDEM: Self = Self {
persist: false,
idem: true,
};
pub const PERSIST: Self = Self {
persist: true,
idem: false,
};
pub const PERSIST_IDEM: Self = Self {
persist: true,
idem: true,
};
}
declare_id!(
MethodId, u64
);
#[derive(Debug)]
pub struct ArgDescriptor {
pub name: &'static str,
pub shape: &'static Shape,
}
impl ServiceDescriptor {
pub const EMPTY: ServiceDescriptor = ServiceDescriptor {
service_name: "<Empty>",
methods: &[],
doc: None,
};
}