diff options
author | Alex Auvolat <alex@adnab.me> | 2023-02-02 15:47:20 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-02-02 15:47:20 +0100 |
commit | d0f40c02b9b74e6e6b852036865ad2b0c0e9370c (patch) | |
tree | cbaea0947e0bc3c6979c6015fd5166ffdfa626ac /src/with_index.rs | |
parent | db1d4411a904bec2d1c2a1c4735ad09cc7f98632 (diff) | |
download | df-consul-d0f40c02b9b74e6e6b852036865ad2b0c0e9370c.tar.gz df-consul-d0f40c02b9b74e6e6b852036865ad2b0c0e9370c.zip |
Documentate
Diffstat (limited to 'src/with_index.rs')
-rw-r--r-- | src/with_index.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/with_index.rs b/src/with_index.rs index 90e06be..adce169 100644 --- a/src/with_index.rs +++ b/src/with_index.rs @@ -3,12 +3,16 @@ use std::fmt::{Debug, Display}; use anyhow::{bail, Result}; use reqwest::Response; +/// Wraps the returned value of an [API call with blocking +/// possibility](https://developer.hashicorp.com/consul/api-docs/features/blocking) with the +/// returned Consul index pub struct WithIndex<T> { value: T, index: usize, } impl<T> WithIndex<T> { + /// (for internal use, mostly) pub fn index_from(resp: &Response) -> Result<WithIndexBuilder<T>> { let index = match resp.headers().get("X-Consul-Index") { Some(v) => v.to_str()?.parse::<usize>()?, @@ -20,10 +24,13 @@ impl<T> WithIndex<T> { }) } + /// Returns the inner value, discarding the index pub fn into_inner(self) -> T { self.value } + /// Returns the Consul index, to be used in future calls to the same API endpoint to make them + /// blocking pub fn index(&self) -> usize { self.index } @@ -60,12 +67,14 @@ impl<T: Display> Display for WithIndex<T> { } } +/// (for internal use, mostly) pub struct WithIndexBuilder<T> { _phantom: std::marker::PhantomData<T>, index: usize, } impl<T> WithIndexBuilder<T> { + /// (for internal use, mostly) pub fn value(self, value: T) -> WithIndex<T> { WithIndex { value, |