diff options
author | Casper <casperneo@uchicago.edu> | 2020-06-18 00:01:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 00:01:48 -0700 |
commit | 12ddc8a92037e879c86b49167d3ecffd28ca2ae9 (patch) | |
tree | d8b4ba07fd3303766bfeea3434a1ae968a6dd8c9 | |
parent | 24ad35709d9a2984a56c572538511b10ce0f3642 (diff) | |
download | flatbuffers-12ddc8a92037e879c86b49167d3ecffd28ca2ae9.tar.gz flatbuffers-12ddc8a92037e879c86b49167d3ecffd28ca2ae9.tar.bz2 flatbuffers-12ddc8a92037e879c86b49167d3ecffd28ca2ae9.zip |
Rust Flexbuffers Documentation update (#5979)
* Update samples and docs
* Fixed a line of documentation
Co-authored-by: Casper Neo <cneo@google.com>
-rw-r--r-- | rust/flexbuffers/README.md | 8 | ||||
-rw-r--r-- | rust/flexbuffers/src/lib.rs | 6 | ||||
-rw-r--r-- | samples/sample_flexbuffers.rs | 15 | ||||
-rw-r--r-- | tests/rust_usage_test/Cargo.toml | 12 |
4 files changed, 37 insertions, 4 deletions
diff --git a/rust/flexbuffers/README.md b/rust/flexbuffers/README.md index c076c0e4..0b3331b6 100644 --- a/rust/flexbuffers/README.md +++ b/rust/flexbuffers/README.md @@ -10,5 +10,13 @@ FlexBuffers' design and implementation allows for a very compact encoding, with automatic sizing of containers to their smallest possible representation (8/16/32/64 bits). Many values and offsets can be encoded in just 8 bits. +FlexBuffers supports [Serde](https://serde.rs/) for automatically serializing +Rust data structures into its binary format. + +## See Examples for Usage: +* [Example](https://github.com/google/flatbuffers/blob/master/samples/sample_flexbuffers.rs) +* [Serde Example](https://github.com/google/flatbuffers/blob/master/samples/sample_flexbuffers_serde.rs) +* [Documentation](https://docs.rs/flexbuffers) + Flexbuffers is the schema-less cousin of [Flatbuffers](https://google.github.io/flatbuffers/). diff --git a/rust/flexbuffers/src/lib.rs b/rust/flexbuffers/src/lib.rs index 8076b340..c5ba05db 100644 --- a/rust/flexbuffers/src/lib.rs +++ b/rust/flexbuffers/src/lib.rs @@ -18,10 +18,12 @@ //! See [Flexbuffer Internals](https://google.github.io/flatbuffers/flatbuffers_internals.html) //! for details on the binary format. //! -//! * [See the examples for usage.](https://github.com/CasperN/flexbuffers/tree/master/examples) +//! See the examples for usage: +//! * [Example](https://github.com/google/flatbuffers/blob/master/samples/sample_flexbuffers.rs) +//! * [Serde Example](https://github.com/google/flatbuffers/blob/master/samples/sample_flexbuffers_serde.rs) //! //! This rust implementation is in progress and, until the 1.0 release, breaking API changes may -/// happen between minor versions. +//! happen between minor versions. // TODO(cneo): serde stuff are behind a default-on feature flag // Reader to Json is behind a default-off feature flag // Serializable structs are Pushable diff --git a/samples/sample_flexbuffers.rs b/samples/sample_flexbuffers.rs index 425279df..efe02c34 100644 --- a/samples/sample_flexbuffers.rs +++ b/samples/sample_flexbuffers.rs @@ -16,6 +16,21 @@ extern crate flexbuffers; use flexbuffers::{BitWidth, Builder, Reader, ReaderError}; + +// In this Example we're creating a monster that corresponds to the following JSON: +// { +// "coins": [5, 10, 25, 25, 25, 100], +// "color": [255, 0, 0, 255], +// "enraged": true, +// "hp": 80, +// "mana": 200, +// "position": [0, 0, 0], +// "velocity": [1, 0, 0], +// "weapons": [ +// "fist", +// {"damage": 15, "name": "great axe"}, +// {"damage": 5, "name": "hammer"}] +// } fn main() { // Create a new Flexbuffer builder. let mut builder = Builder::default(); diff --git a/tests/rust_usage_test/Cargo.toml b/tests/rust_usage_test/Cargo.toml index e02b0b74..406c7282 100644 --- a/tests/rust_usage_test/Cargo.toml +++ b/tests/rust_usage_test/Cargo.toml @@ -6,6 +6,8 @@ authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"] [dependencies] flatbuffers = { path = "../../rust/flatbuffers" } flexbuffers = { path = "../../rust/flexbuffers" } +serde_derive = "1.0" +serde = "1.0" [[bin]] name = "monster_example" @@ -19,13 +21,19 @@ path = "bin/flatbuffers_alloc_check.rs" name = "flexbuffers_alloc_check" path = "bin/flexbuffers_alloc_check.rs" +[[bin]] +name = "sample_flexbuffers" +path = "../../samples/sample_flexbuffers.rs" + +[[bin]] +name = "sample_flexbuffers_serde" +path = "../../samples/sample_flexbuffers_serde.rs" + [dev-dependencies] quickcheck = "0.6" # TODO(rw): look into moving to criterion.rs bencher = "0.1.5" static_assertions = "1.0.0" -serde_derive = "*" -serde = "*" rand = "*" quickcheck_derive = "*" |