Add more docs and debug impls

This commit is contained in:
Lucio Franco
2019-09-04 18:17:16 -04:00
parent 031fcc9026
commit bbc261ae0c
10 changed files with 47 additions and 49 deletions
+13 -3
View File
@@ -1,10 +1,13 @@
use crate::{Error, Status};
use bytes::{Buf, Bytes, IntoBuf};
use http_body::Body as HttpBody;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{
fmt,
pin::Pin,
task::{Context, Poll},
};
pub type BytesBuf = <Bytes as IntoBuf>::Buf;
pub(crate) type BytesBuf = <Bytes as IntoBuf>::Buf;
pub trait Body: sealed::Sealed {
type Data: Buf;
@@ -61,6 +64,7 @@ mod sealed {
pub trait Sealed {}
}
/// A type erased http body.
pub struct BoxBody {
inner: Pin<Box<dyn Body<Data = BytesBuf, Error = Status> + Send + 'static>>,
}
@@ -158,3 +162,9 @@ where
Poll::Ready(v)
}
}
impl fmt::Debug for BoxBody {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BoxBody").finish()
}
}
+2
View File
@@ -40,6 +40,7 @@ where
}
/// A [`Encoder`] that knows how to encode `T`.
#[derive(Debug, Clone)]
pub struct ProstEncoder<T>(PhantomData<T>);
impl<T: Message> Encoder for ProstEncoder<T> {
@@ -59,6 +60,7 @@ impl<T: Message> Encoder for ProstEncoder<T> {
}
/// A [`Decoder`] that knows how to decode `U`.
#[derive(Debug, Clone)]
pub struct ProstDecoder<U>(PhantomData<U>);
impl<U: Message + Default> Decoder for ProstDecoder<U> {
-2
View File
@@ -1,10 +1,8 @@
use std::fmt;
#[allow(dead_code)]
pub type Error = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug)]
#[allow(dead_code)]
pub enum Never {}
impl fmt::Display for Never {
+2 -2
View File
@@ -1,4 +1,5 @@
#![recursion_limit = "512"]
#![warn(missing_debug_implementations)]
//! gRPC implementation
@@ -17,7 +18,7 @@ mod request;
mod response;
mod status;
#[doc(inline)]
#[doc(inline, hidden)]
pub use body::BoxBody;
pub use request::Request;
pub use response::Response;
@@ -27,7 +28,6 @@ pub use tonic_macros::{client, server};
pub(crate) use error::Error;
#[doc(hidden)]
pub mod _codegen {
pub use futures_core::Stream;
pub use futures_util::future::{ok, poll_fn, Ready};
+1
View File
@@ -1,5 +1,6 @@
use crate::metadata::MetadataMap;
/// A gRPC request and metadata from an RPC call.
#[derive(Debug)]
pub struct Request<T> {
metadata: MetadataMap,
-3
View File
@@ -75,7 +75,4 @@ impl<T> Response<T> {
message,
}
}
// pub fn metadata()
// pub fn metadata_bin()
}
+3 -33
View File
@@ -1,8 +1,5 @@
#![allow(dead_code)]
use bytes::Bytes;
use http::header::HeaderValue;
use http::{self, HeaderMap};
use http::header::{HeaderMap, HeaderValue};
use percent_encoding::{percent_decode, percent_encode, EncodeSet, DEFAULT_ENCODE_SET};
use std::{error::Error, fmt};
use tracing::{debug, trace, warn};
@@ -60,22 +57,7 @@ impl Status {
}
}
// Deprecated: this constructor encourages creating statuses with no
// message, hurting later debugging.
#[doc(hidden)]
#[deprecated(note = "use State::new")]
pub fn with_code(code: Code) -> Status {
Status::new(code, String::new())
}
// Deprecated: this constructor is overly long.
#[doc(hidden)]
#[deprecated(note = "use State::new")]
pub fn with_code_and_message(code: Code, message: String) -> Status {
Status::new(code, message)
}
// FIXME: This should probably be made public eventually. Need to decide on
// TODO: This should probably be made public eventually. Need to decide on
// the exact argument type.
#[cfg_attr(not(feature = "h2"), allow(dead_code))]
pub(crate) fn from_error(err: &(dyn Error + 'static)) -> Status {
@@ -107,6 +89,7 @@ impl Status {
None
}
// TODO: bubble this into `transport` and expose generic http2 reasons.
#[cfg(feature = "h2")]
fn from_h2_error(err: &h2::Error) -> Status {
// See https://github.com/grpc/grpc/blob/3977c30/doc/PROTOCOL-HTTP2.md#errors
@@ -195,18 +178,6 @@ impl Status {
&self.details
}
#[doc(hidden)]
#[deprecated(note = "use Status::message")]
pub fn error_message(&self) -> &str {
&self.message
}
#[doc(hidden)]
#[deprecated(note = "use Status::details")]
pub fn binary_error_details(&self) -> &Bytes {
&self.details
}
pub(crate) fn to_header_map(&self) -> Result<HeaderMap, Self> {
let mut header_map = HeaderMap::with_capacity(3);
self.add_header(&mut header_map)?;
@@ -409,7 +380,6 @@ impl Code {
}
}
#[allow(dead_code)]
fn parse_err() -> Code {
trace!("error parsing grpc-status");
Code::Unknown
+12 -3
View File
@@ -6,9 +6,12 @@ use crate::{client::GrpcService, BoxBody};
use futures_util::try_future::{MapErr, TryFutureExt};
use http::Uri;
use hyper::{Request, Response};
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
};
use tower_balance::p2c::Balance;
use tower_buffer::{future::ResponseFuture, Buffer};
use tower_discover::Discover;
@@ -114,3 +117,9 @@ impl Builder {
self.balance_list(vec![uri.into()])
}
}
impl fmt::Debug for Channel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Channel").finish()
}
}
+2
View File
@@ -12,6 +12,7 @@ use std::task::{Context, Poll};
use tower_make::MakeService;
use tower_service::Service;
#[derive(Debug)]
pub struct Server {}
impl Server {
@@ -20,6 +21,7 @@ impl Server {
}
}
#[derive(Debug)]
pub struct Builder {
tls: Option<(Vec<u8>, Vec<u8>)>,
}
+12 -3
View File
@@ -3,9 +3,12 @@ use crate::{transport::Endpoint, BoxBody};
use http::{Request, Response, Uri};
use hyper::client::conn::Builder;
use hyper::client::service::Connect as HyperConnect;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
};
use tower_load::Load;
use tower_reconnect::Reconnect;
use tower_service::Service;
@@ -51,3 +54,9 @@ impl Load for Connection {
0
}
}
impl fmt::Debug for Connection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Connection").finish()
}
}