use super::meta_api::SetMode;
use super::operation::{Arithmetic, Delete, Get, Meta, Set};
#[must_use = "a request does nothing until you call .send()"]
pub struct Request<'a, C, O> {
pub(crate) client: &'a C,
pub(crate) operation: O,
}
impl<'a, C, O> Request<'a, C, O> {
pub(crate) fn new(client: &'a C, operation: O) -> Request<'a, C, O> {
Request { client, operation }
}
pub fn into_operation(self) -> O {
self.operation
}
}
impl<'a, C> Request<'a, C, Get> {
pub fn meta(mut self, meta: Meta) -> Self {
self.operation = self.operation.meta(meta);
self
}
pub fn touch(mut self, ttl: u32) -> Self {
self.operation = self.operation.touch(ttl);
self
}
pub fn no_lru_bump(mut self) -> Self {
self.operation = self.operation.no_lru_bump();
self
}
pub fn unless_cas(mut self, cas: u64) -> Self {
self.operation = self.operation.unless_cas(cas);
self
}
pub fn without_value(mut self) -> Self {
self.operation = self.operation.without_value();
self
}
pub fn lease_ttl(mut self, ttl: u32) -> Self {
self.operation = self.operation.lease_ttl(ttl);
self
}
pub fn refresh_before(mut self, ttl: u32) -> Self {
self.operation = self.operation.refresh_before(ttl);
self
}
}
impl<'a, C> Request<'a, C, Set> {
pub fn ttl(mut self, ttl: u32) -> Self {
self.operation = self.operation.ttl(ttl);
self
}
pub fn mode(mut self, mode: SetMode) -> Self {
self.operation = self.operation.mode(mode);
self
}
pub fn add(mut self) -> Self {
self.operation = self.operation.add();
self
}
pub fn replace(mut self) -> Self {
self.operation = self.operation.replace();
self
}
pub fn append(mut self) -> Self {
self.operation = self.operation.append();
self
}
pub fn prepend(mut self) -> Self {
self.operation = self.operation.prepend();
self
}
pub fn compare_cas(mut self, cas: u64) -> Self {
self.operation = self.operation.compare_cas(cas);
self
}
pub fn version(mut self, version: u64) -> Self {
self.operation = self.operation.version(version);
self
}
pub fn return_cas(mut self) -> Self {
self.operation = self.operation.return_cas();
self
}
pub fn vivify_ttl(mut self, ttl: u32) -> Self {
self.operation = self.operation.vivify_ttl(ttl);
self
}
}
impl<'a, C> Request<'a, C, Delete> {
pub fn compare_cas(mut self, cas: u64) -> Self {
self.operation = self.operation.compare_cas(cas);
self
}
pub fn invalidate(mut self) -> Self {
self.operation = self.operation.invalidate();
self
}
pub fn stale_for(mut self, ttl: u32) -> Self {
self.operation = self.operation.stale_for(ttl);
self
}
}
impl<'a, C> Request<'a, C, Arithmetic> {
pub fn delta(mut self, delta: u64) -> Self {
self.operation = self.operation.delta(delta);
self
}
pub fn initial(mut self, value: u64, ttl: u32) -> Self {
self.operation = self.operation.initial(value, ttl);
self
}
pub fn ttl(mut self, ttl: u32) -> Self {
self.operation = self.operation.ttl(ttl);
self
}
pub fn compare_cas(mut self, cas: u64) -> Self {
self.operation = self.operation.compare_cas(cas);
self
}
pub fn version(mut self, version: u64) -> Self {
self.operation = self.operation.version(version);
self
}
pub fn return_cas(mut self) -> Self {
self.operation = self.operation.return_cas();
self
}
pub fn return_ttl(mut self) -> Self {
self.operation = self.operation.return_ttl();
self
}
}