From d0f40c02b9b74e6e6b852036865ad2b0c0e9370c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 2 Feb 2023 15:47:20 +0100 Subject: Documentate --- src/with_index.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/with_index.rs') 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 { value: T, index: usize, } impl WithIndex { + /// (for internal use, mostly) pub fn index_from(resp: &Response) -> Result> { let index = match resp.headers().get("X-Consul-Index") { Some(v) => v.to_str()?.parse::()?, @@ -20,10 +24,13 @@ impl WithIndex { }) } + /// 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 Display for WithIndex { } } +/// (for internal use, mostly) pub struct WithIndexBuilder { _phantom: std::marker::PhantomData, index: usize, } impl WithIndexBuilder { + /// (for internal use, mostly) pub fn value(self, value: T) -> WithIndex { WithIndex { value, -- cgit v1.2.3