From c6495d31137fc651c6b8110c4e02571c6ff71063 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Fri, 29 Jul 2022 15:17:22 -0400 Subject: [PATCH] Expose bytes crate publicly (#690) * Expose bytes crate publicly * ignore code blocks in readme --- README.md | 38 +++++++++++++++++------------------ src/lib.rs | 2 +- tests/Cargo.toml | 2 +- tests/src/lib.rs | 2 +- tests/src/message_encoding.rs | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e11604496..588a7db6d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Compared to other Protocol Buffers implementations, `prost` First, add `prost` and its public dependencies to your `Cargo.toml`: -``` +```ignore [dependencies] prost = "0.10" # Only necessary if using Protobuf well-known types: @@ -72,7 +72,7 @@ a Rust module. For example, given the `package` specifier: [package]: https://developers.google.com/protocol-buffers/docs/proto#packages -```proto +```proto,ignore package foo.bar; ``` @@ -82,7 +82,7 @@ All Rust types generated from the file will be in the `foo::bar` module. Given a simple message declaration: -```proto +```proto,ignore // Sample message. message Foo { } @@ -90,7 +90,7 @@ message Foo { `prost` will generate the following Rust struct: -```rust +```rust,ignore /// Sample message. #[derive(Clone, Debug, PartialEq, Message)] pub struct Foo { @@ -130,7 +130,7 @@ All `.proto` enumeration types convert to the Rust `i32` type. Additionally, each enumeration type gets a corresponding Rust `enum` type. For example, this `proto` enum: -```proto +```proto,ignore enum PhoneType { MOBILE = 0; HOME = 1; @@ -140,7 +140,7 @@ enum PhoneType { gets this corresponding Rust enum [1]: -```rust +```rust,ignore pub enum PhoneType { Mobile = 0, Home = 1, @@ -150,14 +150,14 @@ pub enum PhoneType { You can convert a `PhoneType` value to an `i32` by doing: -```rust +```rust,ignore PhoneType::Mobile as i32 ``` The `#[derive(::prost::Enumeration)]` annotation added to the generated `PhoneType` adds these associated functions to the type: -```rust +```rust,ignore impl PhoneType { pub fn is_valid(value: i32) -> bool { ... } pub fn from_i32(value: i32) -> Option { ... } @@ -167,7 +167,7 @@ impl PhoneType { so you can convert an `i32` to its corresponding `PhoneType` value by doing, for example: -```rust +```rust,ignore let phone_type = 2i32; match PhoneType::from_i32(phone_type) { @@ -183,7 +183,7 @@ message will have 'accessor' methods to get/set the value of the field as the Rust enum type. For instance, this proto `PhoneNumber` message that has a field named `type` of type `PhoneType`: -```proto +```proto,ignore message PhoneNumber { string number = 1; PhoneType type = 2; @@ -192,7 +192,7 @@ message PhoneNumber { will become the following Rust type [1] with methods `type` and `set_type`: -```rust +```rust,ignore pub struct PhoneNumber { pub number: String, pub r#type: i32, // the `r#` is needed because `type` is a Rust keyword @@ -254,7 +254,7 @@ Oneof fields convert to a Rust enum. Protobuf `oneof`s types are not named, so defines the enum in a module under the struct. For example, a `proto3` message such as: -```proto +```proto,ignore message Foo { oneof widget { int32 quux = 1; @@ -265,7 +265,7 @@ message Foo { generates the following Rust[1]: -```rust +```rust,ignore pub struct Foo { pub widget: Option, } @@ -291,7 +291,7 @@ application's specific needs. Example `.proto` file: -```proto +```proto,ignore syntax = "proto3"; package tutorial; @@ -322,7 +322,7 @@ message AddressBook { and the generated Rust code (`tutorial.rs`): -```rust +```rust,ignore #[derive(Clone, PartialEq, ::prost::Message)] pub struct Person { #[prost(string, tag="1")] @@ -372,7 +372,7 @@ implement introspection capabilities requiring details from the original `.proto `prost` is compatible with `no_std` crates. To enable `no_std` support, disable the `std` features in `prost` and `prost-types`: -``` +```ignore [dependencies] prost = { version = "0.6", default-features = false, features = ["prost-derive"] } # Only necessary if using Protobuf well-known types: @@ -382,7 +382,7 @@ prost-types = { version = "0.6", default-features = false } Additionally, configure `prost-build` to output `BTreeMap`s instead of `HashMap`s for all Protobuf `map` fields in your `build.rs`: -```rust +```rust,ignore let mut config = prost_build::Config::new(); config.btree_map(&["."]); ``` @@ -412,7 +412,7 @@ sequentially occurring tag values by specifying the tag number to skip to with the `tag` attribute on the first field after the gap. The following fields will be tagged sequentially starting from the next number. -```rust +```rust,ignore use prost; use prost::{Enumeration, Message}; @@ -475,7 +475,7 @@ pub enum Gender { If the errors are about missing `autoreconf` or similar, you can probably fix them by running - ``` + ```ignore brew install automake brew install libtool ``` diff --git a/src/lib.rs b/src/lib.rs index 09deda858..acbf289bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,12 @@ #![doc(html_root_url = "https://docs.rs/prost/0.10.1")] #![cfg_attr(not(feature = "std"), no_std)] +#![doc = include_str!("../README.md")] // Re-export the alloc crate for use within derived code. #[doc(hidden)] pub extern crate alloc; // Re-export the bytes crate for use within derived code. -#[doc(hidden)] pub use bytes; mod error; diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 3645348a3..4f165a7a4 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -16,7 +16,7 @@ std = [] [dependencies] anyhow = "1.0.1" -bytes = "1" +# bytes = "1" cfg-if = "1" prost = { path = ".." } prost-types = { path = "../prost-types" } diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 930906572..a9818d682 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -109,7 +109,7 @@ pub mod default_string_escape { use alloc::vec::Vec; use anyhow::anyhow; -use bytes::Buf; +use prost::bytes::Buf; use prost::Message; diff --git a/tests/src/message_encoding.rs b/tests/src/message_encoding.rs index 63072d24d..9533f9f9c 100644 --- a/tests/src/message_encoding.rs +++ b/tests/src/message_encoding.rs @@ -1,5 +1,5 @@ -use bytes::Bytes; use prost::alloc::{borrow::ToOwned, string::String, vec, vec::Vec}; +use prost::bytes::Bytes; use prost::{Enumeration, Message, Oneof}; use crate::check_message;