More documentation generation (#12)

* generate rustdoc comments from .proto file comments

* move imports to top of file

* more docs gen

* trait docs

* more docs

* use singular doc gen fn here

* remove pesky space
This commit is contained in:
John Doneth
2019-09-26 19:41:51 -04:00
committed by Lucio Franco
parent d2355ed83c
commit 8becd257bc
3 changed files with 46 additions and 4 deletions
+13 -1
View File
@@ -1,4 +1,4 @@
use crate::generate_doc_comments;
use crate::{generate_doc_comment, generate_doc_comments};
use proc_macro2::TokenStream;
use prost_build::{Method, Service};
use quote::{format_ident, quote};
@@ -30,6 +30,7 @@ pub(crate) fn generate(service: &Service, proto: &str) -> TokenStream {
Self { inner }
}
/// Check if the service is ready.
pub async fn ready(&mut self) -> Result<(), tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into()))
@@ -51,8 +52,19 @@ pub(crate) fn generate(service: &Service, proto: &str) -> TokenStream {
#[cfg(feature = "transport")]
fn generate_connect(service_ident: &syn::Ident) -> TokenStream {
let doc_example = format!(
"let client = {}::connect(\"http://[::1]:50051\")?;",
service_ident
);
let doc_example = generate_doc_comment(&doc_example);
quote! {
impl #service_ident<tonic::transport::Channel> {
/// Attempt to create a new client by connecting to a given endpoint.
///
/// ```rust,no_run
#doc_example
/// ```
pub fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,