proxy: Convert `convert` from crate to module (#1115)

In e2093e3, we created a `convert` crate when refactoring the proxy's
gRPC bindings into a dedicated crate.

It's not really necessary to handle `convert` as a crate, given that it
holds a single 39-line file that's mostly comments. It's possible to
"vendor" this file in the proxy, and controller-grpc crate doesn't
even need this trait (in fact, the proxy probably doesn't either).
This commit is contained in:
Oliver Gould 2018-06-13 16:18:51 -07:00 committed by GitHub
parent 9f1df963e9
commit fb8d054e96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 10 additions and 51 deletions

6
Cargo.lock generated
View File

@ -125,7 +125,6 @@ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"conduit-proxy-controller-grpc 0.3.0", "conduit-proxy-controller-grpc 0.3.0",
"conduit-proxy-router 0.3.0", "conduit-proxy-router 0.3.0",
"convert 0.3.0",
"deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)", "deflate 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -174,7 +173,6 @@ name = "conduit-proxy-controller-grpc"
version = "0.3.0" version = "0.3.0"
dependencies = [ dependencies = [
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"convert 0.3.0",
"futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "h2 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -196,10 +194,6 @@ dependencies = [
"tower-service 0.1.0 (git+https://github.com/tower-rs/tower)", "tower-service 0.1.0 (git+https://github.com/tower-rs/tower)",
] ]
[[package]]
name = "convert"
version = "0.3.0"
[[package]] [[package]]
name = "crc" name = "crc"
version = "1.7.0" version = "1.7.0"

View File

@ -1,7 +1,6 @@
[workspace] [workspace]
members = [ members = [
"proxy", "proxy",
"proxy/convert",
"proxy/controller-grpc", "proxy/controller-grpc",
"proxy/futures-mpsc-lossy", "proxy/futures-mpsc-lossy",
"proxy/router", "proxy/router",

View File

@ -10,7 +10,6 @@ default = ["flaky_tests"]
flaky_tests = [] flaky_tests = []
[dependencies] [dependencies]
convert = { path = "./convert" }
conduit-proxy-controller-grpc = { path = "./controller-grpc" } conduit-proxy-controller-grpc = { path = "./controller-grpc" }
futures-mpsc-lossy = { path = "./futures-mpsc-lossy" } futures-mpsc-lossy = { path = "./futures-mpsc-lossy" }
conduit-proxy-router = { path = "./router" } conduit-proxy-router = { path = "./router" }

View File

@ -8,8 +8,6 @@ default = []
arbitrary = ["quickcheck"] arbitrary = ["quickcheck"]
[dependencies] [dependencies]
convert = { path = "../convert" }
bytes = "0.4" bytes = "0.4"
futures = "0.1" futures = "0.1"
h2 = "0.1" h2 = "0.1"

View File

@ -1,4 +1,3 @@
extern crate convert;
extern crate h2; extern crate h2;
extern crate http; extern crate http;
extern crate prost; extern crate prost;
@ -9,7 +8,6 @@ extern crate prost_types;
extern crate quickcheck; extern crate quickcheck;
extern crate tower_grpc; extern crate tower_grpc;
use convert::{TryFrom, TryInto};
use std::fmt; use std::fmt;
use std::error::Error; use std::error::Error;
@ -193,9 +191,8 @@ impl<'a> From<&'a ::std::net::SocketAddr> for common::TcpAddress {
// ===== impl common::scheme::Type ===== // ===== impl common::scheme::Type =====
impl<'a> TryInto<String> for &'a common::scheme::Type { impl common::scheme::Type {
type Err = InvalidScheme; pub fn try_to_string(&self) -> Result<String, InvalidScheme> {
fn try_into(self) -> Result<String, Self::Err> {
use self::common::scheme::*; use self::common::scheme::*;
match *self { match *self {
@ -213,13 +210,12 @@ impl<'a> TryInto<String> for &'a common::scheme::Type {
// ===== impl common::HttpMethod ===== // ===== impl common::HttpMethod =====
impl<'a> TryFrom<&'a common::http_method::Type> for http::Method { impl common::http_method::Type {
type Err = InvalidMethod; pub fn try_as_http(&self) -> Result<http::Method, InvalidMethod> {
fn try_from(m: &'a common::http_method::Type) -> Result<Self, Self::Err> {
use self::common::http_method::*; use self::common::http_method::*;
use http::HttpTryFrom; use http::HttpTryFrom;
match *m { match *self {
Type::Registered(reg) => if reg == Registered::Get.into() { Type::Registered(reg) => if reg == Registered::Get.into() {
Ok(http::Method::GET) Ok(http::Method::GET)
} else if reg == Registered::Post.into() { } else if reg == Registered::Post.into() {

View File

@ -1,4 +0,0 @@
[package]
name = "convert"
version = "0.3.0"
publish = false

View File

@ -141,7 +141,7 @@ impl Stream for TapEvents {
_ => continue, _ => continue,
} }
if let Ok(te) = (&ev).try_into() { if let Ok(te) = TapEvent::try_from(&ev) {
// TODO Do limit checks here. // TODO Do limit checks here.
return Ok(Some(te).into()); return Ok(Some(te).into());
} }

View File

@ -15,25 +15,3 @@ pub trait TryFrom<T>: Sized {
#[doc(hidden)] #[doc(hidden)]
fn try_from(t: T) -> Result<Self, Self::Err>; fn try_from(t: T) -> Result<Self, Self::Err>;
} }
/// Private trait for generic methods with fallible conversions.
///
/// This trait is similar to the `TryInto` trait proposed in the standard
/// library, and should be removed when `TryInto` is stabilized.
pub trait TryInto<T>: Sized {
type Err;
#[doc(hidden)]
fn try_into(self) -> Result<T, Self::Err>;
}
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
{
type Err = U::Err;
fn try_into(self) -> Result<U, Self::Err> {
U::try_from(self)
}
}

View File

@ -4,7 +4,6 @@
extern crate bytes; extern crate bytes;
extern crate conduit_proxy_controller_grpc; extern crate conduit_proxy_controller_grpc;
extern crate convert;
extern crate env_logger; extern crate env_logger;
extern crate deflate; extern crate deflate;
#[macro_use] #[macro_use]
@ -69,6 +68,7 @@ mod bind;
pub mod config; pub mod config;
mod connection; mod connection;
pub mod control; pub mod control;
pub mod convert;
pub mod ctx; pub mod ctx;
mod dns; mod dns;
mod drain; mod drain;

View File

@ -9,7 +9,7 @@ use ipnet::{Contains, Ipv4Net, Ipv6Net};
use super::Event; use super::Event;
use conduit_proxy_controller_grpc::common::ip_address; use conduit_proxy_controller_grpc::common::ip_address;
use conduit_proxy_controller_grpc::tap::observe_request; use conduit_proxy_controller_grpc::tap::observe_request;
use convert::*; use convert::TryFrom;
use ctx; use ctx;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -358,7 +358,7 @@ impl<'a> TryFrom<&'a observe_request::match_::Http> for HttpMatch {
.as_ref() .as_ref()
.ok_or_else(|| InvalidMatch::Empty) .ok_or_else(|| InvalidMatch::Empty)
.and_then(|s| { .and_then(|s| {
s.try_into() s.try_to_string()
.map(HttpMatch::Scheme) .map(HttpMatch::Scheme)
.map_err(|_| InvalidMatch::InvalidScheme) .map_err(|_| InvalidMatch::InvalidScheme)
}), }),
@ -367,7 +367,7 @@ impl<'a> TryFrom<&'a observe_request::match_::Http> for HttpMatch {
.as_ref() .as_ref()
.ok_or_else(|| InvalidMatch::Empty) .ok_or_else(|| InvalidMatch::Empty)
.and_then(|m| { .and_then(|m| {
m.try_into() m.try_as_http()
.map(HttpMatch::Method) .map(HttpMatch::Method)
.map_err(|_| InvalidMatch::InvalidHttpMethod) .map_err(|_| InvalidMatch::InvalidHttpMethod)
}), }),

View File

@ -8,7 +8,6 @@
pub extern crate bytes; pub extern crate bytes;
pub extern crate conduit_proxy_controller_grpc; pub extern crate conduit_proxy_controller_grpc;
extern crate conduit_proxy; extern crate conduit_proxy;
pub extern crate convert;
extern crate futures; extern crate futures;
extern crate h2; extern crate h2;
pub extern crate http; pub extern crate http;