diff options
author | doug tangren <d.tangren@gmail.com> | 2018-12-24 13:11:02 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 13:11:02 +0900 |
commit | ebe4a2d80dffb89d1fbceb14dbac3dc6da004fb8 (patch) | |
tree | ab56800af4f921388035fd6d9f318f9ec0bd97cc /src | |
parent | 3c06c3a11ba1f7d362bde8b14d94b07b529850e8 (diff) |
update to 2018 edition (#141)
* update to 2018 edition
* remove more externs
* bump version
Diffstat (limited to 'src')
-rw-r--r-- | src/builder.rs | 22 | ||||
-rw-r--r-- | src/errors.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 72 | ||||
-rw-r--r-- | src/read.rs | 8 | ||||
-rw-r--r-- | src/rep.rs | 1 | ||||
-rw-r--r-- | src/tarball.rs | 11 | ||||
-rw-r--r-- | src/transport.rs | 8 | ||||
-rw-r--r-- | src/tty.rs | 25 |
8 files changed, 61 insertions, 91 deletions
diff --git a/src/builder.rs b/src/builder.rs index cd086ca..bf7500f 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,21 +1,17 @@ //! Interfaces for building various structures -// Std lib -use std::cmp::Eq; -use std::collections::{BTreeMap, HashMap}; -use std::hash::Hash; -use std::iter::IntoIterator; -use std::iter::Peekable; - -// Third party +use crate::{errors::Error, Result}; use serde::Serialize; -use serde_json::{self, map::Map, Value}; +use serde_derive::Serialize; +use serde_json::{self, json, map::Map, Value}; +use std::{ + cmp::Eq, + collections::{BTreeMap, HashMap}, + hash::Hash, + iter::{IntoIterator, Peekable}, +}; use url::form_urlencoded; -// Ours -use errors::Error; -use Result; - #[derive(Default)] pub struct PullOptions { params: HashMap<&'static str, String>, diff --git a/src/errors.rs b/src/errors.rs index 8392971..f363ffd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,10 +3,7 @@ use http; use hyper::{self, StatusCode}; use serde_json::Error as SerdeError; -use std::error::Error as StdError; -use std::fmt; -use std::io::Error as IoError; -use std::string::FromUtf8Error; +use std::{error::Error as StdError, fmt, io::Error as IoError, string::FromUtf8Error}; #[derive(Debug)] pub enum Error { @@ -3,9 +3,6 @@ //! # examples //! //! ```no_run -//! extern crate shiplift; -//! extern crate tokio; -//! //! use tokio::prelude::Future; //! //! let docker = shiplift::Docker::new(); @@ -19,30 +16,6 @@ //! tokio::run(fut); //! ``` -#[macro_use] -extern crate log; -extern crate byteorder; -extern crate bytes; -extern crate flate2; -extern crate futures; -extern crate http; -extern crate hyper; -extern crate hyper_openssl; -#[cfg(feature = "unix-socket")] -extern crate hyperlocal; -extern crate mime; -extern crate openssl; -extern crate tar; -extern crate url; -#[macro_use] -extern crate serde_derive; -extern crate serde; -#[macro_use] -extern crate serde_json; -extern crate tokio; -extern crate tokio_codec; -extern crate tokio_io; - pub mod builder; pub mod errors; pub mod read; @@ -52,37 +25,36 @@ pub mod tty; mod tarball; -pub use builder::{ - BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions, - ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions, - LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RmContainerOptions, - VolumeCreateOptions, +pub use crate::{ + builder::{ + BuildOptions, ContainerConnectionOptions, ContainerFilter, ContainerListOptions, + ContainerOptions, EventsOptions, ExecContainerOptions, ImageFilter, ImageListOptions, + LogsOptions, NetworkCreateOptions, NetworkListOptions, PullOptions, RmContainerOptions, + VolumeCreateOptions, + }, + errors::Error, +}; +use crate::{ + read::StreamReader, + rep::{ + Change, Container as ContainerRep, ContainerCreateInfo, ContainerDetails, Event, Exit, + History, Image as ImageRep, ImageDetails, Info, NetworkCreateInfo, + NetworkDetails as NetworkInfo, SearchResult, Stats, Status, Top, Version, + Volume as VolumeRep, VolumeCreateInfo, Volumes as VolumesRep, + }, + transport::{tar, Transport}, + tty::TtyDecoder, }; -pub use errors::Error; use futures::{future::Either, Future, IntoFuture, Stream}; -use hyper::client::HttpConnector; -use hyper::Body; -use hyper::{Client, Method, Uri}; +use hyper::{client::HttpConnector, Body, Client, Method, Uri}; use hyper_openssl::HttpsConnector; #[cfg(feature = "unix-socket")] use hyperlocal::UnixConnector; use mime::Mime; use openssl::ssl::{SslConnector, SslFiletype, SslMethod}; -use read::StreamReader; -use rep::{ - Change, Container as ContainerRep, ContainerCreateInfo, ContainerDetails, Event, Exit, History, - Image as ImageRep, ImageDetails, Info, NetworkCreateInfo, NetworkDetails as NetworkInfo, - SearchResult, Stats, Status, Top, Version, Volume as VolumeRep, VolumeCreateInfo, - Volumes as VolumesRep, -}; use serde_json::Value; -use std::borrow::Cow; -use std::env; -use std::path::Path; -use std::time::Duration; +use std::{borrow::Cow, env, path::Path, time::Duration}; use tokio_codec::{FramedRead, LinesCodec}; -use transport::{tar, Transport}; -use tty::TtyDecoder; use url::form_urlencoded; /// Represents the result of all docker operations @@ -769,7 +741,7 @@ impl<'a, 'b> Volume<'a, 'b> { } } -// https://docs.docker.com/reference/api/docker_remote_api_v1.17/ +// https://docs.docker.com/reference/api/ impl Docker { /// constructs a new Docker instance for a docker host listening at a url specified by an env var `DOCKER_HOST`, /// falling back on unix:///var/run/docker.sock diff --git a/src/read.rs b/src/read.rs index 847ee21..b9dc5ef 100644 --- a/src/read.rs +++ b/src/read.rs @@ -1,8 +1,10 @@ -use errors::Error; +use crate::errors::Error; use futures::{Async, Stream}; use hyper::Chunk; -use std::cmp; -use std::io::{self, Read}; +use std::{ + cmp, + io::{self, Read}, +}; use tokio_io::AsyncRead; /* @@ -1,5 +1,6 @@ //! Rust representations of docker json structures +use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/src/tarball.rs b/src/tarball.rs index acbe47a..06a0362 100644 --- a/src/tarball.rs +++ b/src/tarball.rs @@ -1,8 +1,9 @@ -use flate2::write::GzEncoder; -use flate2::Compression; -use std::fs::{self, File}; -use std::io::{self, Write}; -use std::path::{Path, MAIN_SEPARATOR}; +use flate2::{write::GzEncoder, Compression}; +use std::{ + fs::{self, File}, + io::{self, Write}, + path::{Path, MAIN_SEPARATOR}, +}; use tar::Builder; // todo: this is pretty involved. (re)factor this into its own crate diff --git a/src/transport.rs b/src/transport.rs index 41d8694..432c5df 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -1,6 +1,6 @@ //! Transports for communicating with the docker daemon -use self::super::{Error, Result}; +use crate::{Error, Result}; use futures::{ future::{self, Either}, Future, IntoFuture, Stream, @@ -14,7 +14,9 @@ use hyper_openssl::HttpsConnector; use hyperlocal::UnixConnector; #[cfg(feature = "unix-socket")] use hyperlocal::Uri as DomainUri; +use log::debug; use mime::Mime; +use serde_derive::{Deserialize, Serialize}; use serde_json; use std::fmt; use tokio_io::{AsyncRead, AsyncWrite}; @@ -226,12 +228,12 @@ impl Transport { method: Method, endpoint: &str, body: Option<(B, Mime)>, - ) -> impl Future<Item = ::tty::Multiplexed, Error = Error> + ) -> impl Future<Item = crate::tty::Multiplexed, Error = Error> where B: Into<Body> + 'static, { self.stream_upgrade(method, endpoint, body) - .map(|u| ::tty::Multiplexed::new(u)) + .map(|u| crate::tty::Multiplexed::new(u)) } /// Extract the error message content from an HTTP response that @@ -1,12 +1,11 @@ +use crate::errors::Error; use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; use bytes::BytesMut; -use errors::Error; -use std::io::Cursor; -use tokio_codec::Decoder; - use futures::{self, Async}; use hyper::rt::{Future, Stream}; -use std::io; +use log::trace; +use std::io::{self, Cursor}; +use tokio_codec::Decoder; use tokio_io::{AsyncRead, AsyncWrite}; #[derive(Debug)] @@ -25,12 +24,12 @@ pub enum StreamType { /// A multiplexed stream. pub struct Multiplexed { stdin: Box<AsyncWrite>, - chunks: Box<futures::Stream<Item = Chunk, Error = ::Error>>, + chunks: Box<futures::Stream<Item = Chunk, Error = crate::Error>>, } pub struct MultiplexedBlocking { stdin: Box<AsyncWrite>, - chunks: Box<Iterator<Item = Result<Chunk, ::Error>>>, + chunks: Box<Iterator<Item = Result<Chunk, crate::Error>>>, } /// Represent the current state of the decoding of a TTY frame @@ -164,17 +163,17 @@ impl Multiplexed { impl futures::Stream for Multiplexed { type Item = Chunk; - type Error = ::Error; + type Error = crate::Error; - fn poll(&mut self) -> Result<Async<Option<Chunk>>, ::Error> { + fn poll(&mut self) -> Result<Async<Option<Chunk>>, crate::Error> { self.chunks.poll() } } impl Iterator for MultiplexedBlocking { - type Item = Result<Chunk, ::Error>; + type Item = Result<Chunk, crate::Error>; - fn next(&mut self) -> Option<Result<Chunk, ::Error>> { + fn next(&mut self) -> Option<Result<Chunk, crate::Error>> { self.chunks.next() } } @@ -199,7 +198,7 @@ macro_rules! delegate_io_write { delegate_io_write!(Multiplexed); delegate_io_write!(MultiplexedBlocking); -pub fn chunks<S>(stream: S) -> impl futures::Stream<Item = Chunk, Error = ::Error> +pub fn chunks<S>(stream: S) -> impl futures::Stream<Item = Chunk, Error = crate::Error> where S: AsyncRead, { @@ -227,7 +226,7 @@ where }); util::stop_on_err(stream, |e| e.kind() != io::ErrorKind::UnexpectedEof) - .map_err(|e| ::Error::from(e)) + .map_err(|e| crate::Error::from(e)) } mod util { |