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