diff options
author | Wojciech Kępka <46892771+wojciechkepka@users.noreply.github.com> | 2021-02-06 08:14:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-06 02:14:39 -0500 |
commit | 4e3f69c34a177697af940849fced1a284fc09449 (patch) | |
tree | 66fdf4f6bc722b2f3181dbb9664f29e2d8fc3a60 | |
parent | ef3dfad8f691f64e41fb1d369399471cde6ad8c0 (diff) |
Simplify api, get rid of unnecessary lifetimes (#252)
* Get rid of explicit lifetimes
* more lifetimes ellided
* Fix examples
* Minor fix
-rw-r--r-- | examples/attach.rs | 3 | ||||
-rw-r--r-- | examples/logs.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 77 |
3 files changed, 48 insertions, 37 deletions
diff --git a/examples/attach.rs b/examples/attach.rs index e4ed637..769bc64 100644 --- a/examples/attach.rs +++ b/examples/attach.rs @@ -9,7 +9,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { .nth(1) .expect("You need to specify a container id"); - let tty_multiplexer = docker.containers().get(&id).attach().await?; + let containers = docker.containers(); + let tty_multiplexer = containers.get(&id).attach().await?; let (mut reader, _writer) = tty_multiplexer.split(); diff --git a/examples/logs.rs b/examples/logs.rs index 73c8045..eb3bdb5 100644 --- a/examples/logs.rs +++ b/examples/logs.rs @@ -9,8 +9,9 @@ async fn main() { .nth(1) .expect("You need to specify a container id"); - let mut logs_stream = docker - .containers() + let containers = docker.containers(); + + let mut logs_stream = containers .get(&id) .logs(&LogsOptions::builder().stdout(true).stderr(true).build()); @@ -60,7 +60,7 @@ use mime::Mime; #[cfg(feature = "tls")] use openssl::ssl::{SslConnector, SslFiletype, SslMethod}; use serde_json::Value; -use std::{borrow::Cow, env, io, io::Read, iter, path::Path, time::Duration}; +use std::{env, io, io::Read, iter, path::Path, time::Duration}; use url::form_urlencoded; /// Represents the result of all docker operations @@ -75,17 +75,17 @@ pub struct Docker { /// Interface for accessing and manipulating a named docker image pub struct Image<'a> { docker: &'a Docker, - name: Cow<'a, str>, + name: String, } impl<'a> Image<'a> { /// Exports an interface for operations that may be performed against a named image pub fn new<S>( - docker: &'a Docker, + docker: &Docker, name: S, - ) -> Self + ) -> Image where - S: Into<Cow<'a, str>>, + S: Into<String>, { Image { docker, @@ -189,10 +189,13 @@ impl<'a> Images<'a> { } /// Returns a reference to a set of operations available for a named image - pub fn get( + pub fn get<S>( &self, - name: &'a str, - ) -> Image<'a> { + name: S, + ) -> Image<'a> + where + S: Into<String>, + { Image::new(self.docker, name) } @@ -273,7 +276,7 @@ impl<'a> Images<'a> { /// Interface for accessing and manipulating a docker container pub struct Container<'a> { docker: &'a Docker, - id: Cow<'a, str>, + id: String, } impl<'a> Container<'a> { @@ -283,7 +286,7 @@ impl<'a> Container<'a> { id: S, ) -> Self where - S: Into<Cow<'a, str>>, + S: Into<String>, { Container { docker, @@ -628,10 +631,13 @@ impl<'a> Containers<'a> { } /// Returns a reference to a set of operations available to a specific container instance - pub fn get( + pub fn get<S>( &self, - name: &'a str, - ) -> Container<'a> { + name: S, + ) -> Container + where + S: Into<String>, + { Container::new(self.docker, name) } @@ -789,7 +795,7 @@ pub struct Networks<'a> { impl<'a> Networks<'a> { /// Exports an interface for interacting with docker Networks - pub fn new(docker: &'a Docker) -> Networks<'a> { + pub fn new(docker: &Docker) -> Networks { Networks { docker } } @@ -806,10 +812,13 @@ impl<'a> Networks<'a> { } /// Returns a reference to a set of operations available to a specific network instance - pub fn get<'b>( + pub fn get<S>( &self, - id: &'b str, - ) -> Network<'a, 'b> { + id: S, + ) -> Network + where + S: Into<String>, + { Network::new(self.docker, id) } @@ -828,19 +837,19 @@ impl<'a> Networks<'a> { } /// Interface for accessing and manipulating a docker network -pub struct Network<'a, 'b> { +pub struct Network<'a> { docker: &'a Docker, - id: Cow<'b, str>, + id: String, } -impl<'a, 'b> Network<'a, 'b> { +impl<'a> Network<'a> { /// Exports an interface exposing operations against a network instance pub fn new<S>( - docker: &'a Docker, + docker: &Docker, id: S, - ) -> Network<'a, 'b> + ) -> Network where - S: Into<Cow<'b, str>>, + S: Into<String>, { Network { docker, @@ -908,7 +917,7 @@ pub struct Volumes<'a> { impl<'a> Volumes<'a> { /// Exports an interface for interacting with docker volumes - pub fn new(docker: &'a Docker) -> Volumes<'a> { + pub fn new(docker: &Docker) -> Volumes { Volumes { docker } } @@ -936,28 +945,28 @@ impl<'a> Volumes<'a> { } /// Returns a reference to a set of operations available for a named volume - pub fn get<'b>( + pub fn get( &self, - name: &'b str, - ) -> Volume<'a, 'b> { + name: &str, + ) -> Volume { Volume::new(self.docker, name) } } /// Interface for accessing and manipulating a named docker volume -pub struct Volume<'a, 'b> { +pub struct Volume<'a> { docker: &'a Docker, - name: Cow<'b, str>, + name: String, } -impl<'a, 'b> Volume<'a, 'b> { +impl<'a> Volume<'a> { /// Exports an interface for operations that may be performed against a named volume pub fn new<S>( - docker: &'a Docker, + docker: &Docker, name: S, - ) -> Volume<'a, 'b> + ) -> Volume where - S: Into<Cow<'b, str>>, + S: Into<String>, { Volume { docker, @@ -1139,7 +1148,7 @@ impl Docker { /// Returns a stream of docker events pub fn events<'a>( &'a self, - opts: &'a EventsOptions, + opts: &EventsOptions, ) -> impl Stream<Item = Result<Event>> + Unpin + 'a { let mut path = vec!["/events".to_owned()]; if let Some(query) = opts.serialize() { |