Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bytes crate publicly #690

Merged
merged 4 commits into from Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
```

Expand All @@ -82,15 +82,15 @@ 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 {
}
```

`prost` will generate the following Rust struct:

```rust
```rust,ignore
/// Sample message.
#[derive(Clone, Debug, PartialEq, Message)]
pub struct Foo {
Expand Down Expand Up @@ -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;
Expand All @@ -140,7 +140,7 @@ enum PhoneType {

gets this corresponding Rust enum [1]:

```rust
```rust,ignore
pub enum PhoneType {
Mobile = 0,
Home = 1,
Expand All @@ -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<PhoneType> { ... }
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -265,7 +265,7 @@ message Foo {

generates the following Rust[1]:

```rust
```rust,ignore
pub struct Foo {
pub widget: Option<foo::Widget>,
}
Expand All @@ -291,7 +291,7 @@ application's specific needs.

Example `.proto` file:

```proto
```proto,ignore
syntax = "proto3";
package tutorial;

Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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:
Expand All @@ -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(&["."]);
```
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion 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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ std = []

[dependencies]
anyhow = "1.0.1"
bytes = "1"
# bytes = "1"
cfg-if = "1"
prost = { path = ".." }
prost-types = { path = "../prost-types" }
Expand Down
2 changes: 1 addition & 1 deletion tests/src/lib.rs
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion 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;
Expand Down