etcd/lib.rs
1//! Crate `etcd` provides a client for [etcd](https://github.com/coreos/etcd), a distributed
2//! key-value store from [CoreOS](https://coreos.com/).
3//!
4//! The client uses etcd's v2 API. Support for the v3 API is planned, and will be added via
5//! separate types for backwards compatibility and to support both APIs simultaneously.
6//!
7//! The client uses asynchronous I/O, backed by the `futures` and `tokio` crates, and requires
8//! both to be used alongside. Where possible, futures are returned using "impl Trait" instead of
9//! boxing.
10//!
11//! The client is tested against etcd 2.3.8.
12//!
13//! # Usage
14//!
15//! `Client` is an HTTP client required for all API calls. It can be constructed to use HTTP or
16//! HTTPS, and supports authenticating to the etcd cluster via HTTP basic authentication (username
17//! and password) and/or X.509 client certificates.
18//!
19//! To get basic information about the health and versions of etcd running in a cluster, use the
20//! `Client::health` and `Client::versions` methods, respectively. All other API calls are made by
21//! passing a `Client` reference to the functions in the `auth`, `kv`, `members`, and `stats`
22//! modules. These modules contain functions for API calls to the authentication and authorization
23//! API, the primary key-value store API, the cluster membership API, and statistics API,
24//! respectively.
25//!
26//! # Examples
27//!
28//! Basic usage:
29//!
30//! ```no_run
31//! use etcd::Client;
32//! use etcd::kv::{self, Action};
33//! use futures::Future;
34//! use tokio::runtime::Runtime;
35//!
36//! fn main() {
37//! // Create a client to access a single cluster member. Addresses of multiple cluster
38//! // members can be provided and the client will try each one in sequence until it
39//! // receives a successful response.
40//! let client = Client::new(&["http://etcd.example.com:2379"], None).unwrap();
41//!
42//! // Set the key "/foo" to the value "bar" with no expiration.
43//! let work = kv::set(&client, "/foo", "bar", None).and_then(move |_| {
44//! // Once the key has been set, ask for details about it.
45//! let get_request = kv::get(&client, "/foo", kv::GetOptions::default());
46//!
47//! get_request.and_then(|response| {
48//! // The information returned tells you what kind of operation was performed.
49//! assert_eq!(response.data.action, Action::Get);
50//!
51//! // The value of the key is what we set it to previously.
52//! assert_eq!(response.data.node.value, Some("bar".to_string()));
53//!
54//! // Each API call also returns information about the etcd cluster extracted from
55//! // HTTP response headers.
56//! assert!(response.cluster_info.etcd_index.is_some());
57//!
58//! Ok(())
59//! })
60//! });
61//!
62//! // Start the event loop, driving the asynchronous code to completion.
63//! assert!(Runtime::new().unwrap().block_on(work).is_ok());
64//! }
65//! ```
66//!
67//! # Cargo features
68//!
69//! Crate `etcd` has one Cargo feature, `tls`, which adds HTTPS support via the `Client::https`
70//! constructor. This feature is enabled by default.
71#![deny(missing_debug_implementations, missing_docs, warnings)]
72
73pub use crate::client::{BasicAuth, Client, ClusterInfo, Health, Response};
74pub use crate::error::{ApiError, Error};
75pub use crate::version::VersionInfo;
76
77pub mod auth;
78pub mod kv;
79pub mod members;
80pub mod stats;
81
82mod client;
83mod error;
84mod first_ok;
85mod http;
86mod options;
87mod version;