diff options
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 13 | ||||
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | Cargo.toml | 23 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.android | 15 | ||||
-rw-r--r-- | README.md | 55 | ||||
-rw-r--r-- | cargo2android.json | 4 | ||||
-rw-r--r-- | src/code_writer.rs | 3 | ||||
-rw-r--r-- | src/customize.rs | 21 | ||||
-rw-r--r-- | src/enums.rs | 20 | ||||
-rw-r--r-- | src/extensions.rs | 5 | ||||
-rw-r--r-- | src/field/mod.rs | 33 | ||||
-rw-r--r-- | src/lib.rs | 92 | ||||
-rw-r--r-- | src/message.rs | 15 | ||||
-rw-r--r-- | src/oneof.rs | 17 | ||||
-rw-r--r-- | src/protobuf_name.rs | 4 | ||||
-rw-r--r-- | src/rust_types_values.rs | 3 | ||||
-rw-r--r-- | src/scope.rs | 17 |
20 files changed, 242 insertions, 123 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 0be67b3..8ec5394 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "3eabf141db9d0d69961ba8a1eaf2907c7aeb8ff9" - } -} + "sha1": "ec31ce829473039ac598ca6fdcb245cbd6fa82ba" + }, + "path_in_vcs": "protobuf-codegen" +}
\ No newline at end of file @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --dependencies --tests. +// This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. package { @@ -23,6 +23,8 @@ license { rust_library_host { name: "libprotobuf_codegen", crate_name: "protobuf_codegen", + cargo_env_compat: true, + cargo_pkg_version: "2.27.1", srcs: ["src/lib.rs"], edition: "2015", rustlibs: [ @@ -31,8 +33,10 @@ rust_library_host { } rust_test_host { - name: "protobuf-codegen_host_test_src_lib", + name: "protobuf-codegen_test_src_lib", crate_name: "protobuf_codegen", + cargo_env_compat: true, + cargo_pkg_version: "2.27.1", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -48,6 +52,8 @@ rust_test_host { rust_binary_host { name: "protoc-gen-rust", crate_name: "protoc_gen_rust", + cargo_env_compat: true, + cargo_pkg_version: "2.27.1", srcs: ["src/bin/protoc-gen-rust.rs"], edition: "2015", rustlibs: [ @@ -55,6 +61,3 @@ rust_binary_host { "libprotobuf_codegen", ], } - -// dependent_library ["feature_list"] -// protobuf-2.22.1 @@ -4,13 +4,13 @@ version = 3 [[package]] name = "protobuf" -version = "2.22.1" +version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b7f4a129bb3754c25a4e04032a90173c68f85168f77118ac4cb4936e7f06f92" +checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" [[package]] name = "protobuf-codegen" -version = "2.22.1" +version = "2.27.1" dependencies = [ "protobuf", ] @@ -3,21 +3,27 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] name = "protobuf-codegen" -version = "2.22.1" +version = "2.27.1" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] -description = "Code generator for rust-protobuf.\n\nIncludes a library and `protoc-gen-rust` binary.\n\nSee `protoc-rust` and `protobuf-codegen-pure` crates.\n" +description = """ +Code generator for rust-protobuf. + +Includes a library and `protoc-gen-rust` binary. + +See `protoc-rust` and `protobuf-codegen-pure` crates. +""" homepage = "https://github.com/stepancheg/rust-protobuf/" license = "MIT" repository = "https://github.com/stepancheg/rust-protobuf/" + [package.metadata.docs.rs] all-features = true @@ -33,5 +39,6 @@ test = false name = "protobuf-bin-gen-rust-do-not-use" path = "src/bin/protobuf-bin-gen-rust-do-not-use.rs" test = false + [dependencies.protobuf] -version = "=2.22.1" +version = "=2.27.1" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 07931fd..3400e66 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "protobuf-codegen" -version = "2.22.1" +version = "2.27.1" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] license = "MIT" homepage = "https://github.com/stepancheg/rust-protobuf/" @@ -17,7 +17,7 @@ See `protoc-rust` and `protobuf-codegen-pure` crates. bench = false [dependencies] -protobuf = { path = "../protobuf", version = "=2.22.1" } +protobuf = { path = "../protobuf", version = "=2.27.1" } [[bin]] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/protobuf-codegen/protobuf-codegen-2.22.1.crate" + value: "https://static.crates.io/crates/protobuf-codegen/protobuf-codegen-2.27.1.crate" } - version: "2.22.1" + version: "2.27.1" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 4 + year: 2022 + month: 3 day: 1 } } diff --git a/README.android b/README.android deleted file mode 100644 index a75eb35..0000000 --- a/README.android +++ /dev/null @@ -1,15 +0,0 @@ -Since we do not run build.rs during an Android build, -we need to set up the version number in src/lib.rs -until we have a smarter way to patch it based on new -version number in Cargo.toml. - -To update this package, please make sure that the following code -in src/lib.rs is up to data. - - // Hack: hard code version number here because Android.bp - // rust modules cannot pass it though env variable yet. - w.write_generated_by("rust-protobuf", "2.16.2"); - -If there are non-trivial changes in build.rs or src/lib.rs, -please rerun cargo2android.py and verify the differences in -Android.bp and src/lib.rs. @@ -1,35 +1,49 @@ -# protobuf-codegen +<!-- cargo-sync-readme start --> -This crate contains protobuf code generator and a `protoc-gen-rust` `protoc` plugin. +# Protobuf code generator -## protoc-gen-rust +This crate contains protobuf code generator implementation +and a `protoc-gen-rust` `protoc` plugin. -`protoc-gen-rust` implements standard protobuf `protoc` plugin conventions. +This crate: +* provides `protoc-gen-rust` plugin for `protoc` command +* implement protobuf codegen -Probably you do not want to use it directly in Rust environment, there are easier to use alternatives: +This crate is not meant to be used directly, in fact, it does not provide any public API +(except for `protoc-gen-rust` binary). -* [protoc-rust crate](https://github.com/stepancheg/rust-protobuf/tree/master/protoc-rust) - which can be invoked programmatically from `build.rs` of your project - which requires only `protoc` in `$PATH` but not `protoc-gen-rust`. -* [protobuf-codegen-pure crate](https://github.com/stepancheg/rust-protobuf/tree/master/protobuf-codegen-pure) - which behaves like protoc-rust, but does not depend on `protoc` binary +Code can be generated with either: +* `protoc-gen-rust` plugin for `protoc` or +* [`protoc-rust`](https://docs.rs/protoc) crate + (code generator which depends on `protoc` binary for parsing of `.proto` files) +* [`protobuf-codegen-pure`](https://docs.rs/protobuf-codegen-pure) crate, + similar API to `protoc-rust`, but uses pure rust parser of `.proto` files. -## But if you really want to use that plugin, here's the instruction +# `protoc-gen-rust` plugin for `protoc` + +When non-cargo build system is used, consider using standard protobuf code generation pattern: +`protoc` command does all the work of handling paths and parsing `.proto` files. +When `protoc` is invoked with `--rust_out=` option, it invokes `protoc-gen-rust` plugin. +provided by this crate. + +When building with cargo, consider using `protoc-rust` or `protobuf-codegen-pure` crates. + +## How to use `protoc-gen-rust` if you have to (Note `protoc` can be invoked programmatically with -[protoc crate](https://github.com/stepancheg/rust-protobuf/tree/master/protoc/)) +[protoc crate](https://docs.rs/protoc)) 0) Install protobuf for `protoc` binary. On OS X [Homebrew](https://github.com/Homebrew/brew) can be used: -``` +```sh brew install protobuf ``` On Ubuntu, `protobuf-compiler` package can be installed: -``` +```sh apt-get install protobuf-compiler ``` @@ -44,14 +58,23 @@ It can be installed either from source or with `cargo install protobuf` command. If you installed it with cargo, it should be -``` +```sh PATH="$HOME/.cargo/bin:$PATH" ``` 3) Generate .rs files: -``` +```sh protoc --rust_out . foo.proto ``` This will generate .rs files in current directory. + +# Version 2 + +This is documentation for version 2 of the crate. + +[Version 3 of the crate](https://docs.rs/protobuf-codegen/%3E=3.0.0-alpha) +(currently in development) encapsulates both `protoc` and pure codegens in this crate. + +<!-- cargo-sync-readme end --> diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..341300b --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,4 @@ +{ + "run": true, + "tests": true +}
\ No newline at end of file diff --git a/src/code_writer.rs b/src/code_writer.rs index f6d4c07..50eaeb8 100644 --- a/src/code_writer.rs +++ b/src/code_writer.rs @@ -1,8 +1,9 @@ // TODO: used by grpc-rust, should move it into separate crate. #![doc(hidden)] -use inside::protobuf_crate_path; use std::io::Write; + +use inside::protobuf_crate_path; use Customize; /// Field visibility. diff --git a/src/customize.rs b/src/customize.rs index f8e73aa..b3415ab 100644 --- a/src/customize.rs +++ b/src/customize.rs @@ -1,3 +1,4 @@ +use protobuf::descriptor::EnumOptions; use protobuf::descriptor::FieldOptions; use protobuf::descriptor::FileOptions; use protobuf::descriptor::MessageOptions; @@ -20,6 +21,8 @@ pub struct Customize { pub serde_derive: Option<bool>, /// When `serde_derive` is set, serde annotations will be guarded with `#[cfg(cfg, ...)]`. pub serde_derive_cfg: Option<String>, + /// When `serde_derive` is set, use attribute rename_all + pub serde_rename_all: Option<String>, /// Enable lite runtime pub lite_runtime: Option<bool>, /// Generate `mod.rs` in the output directory. @@ -71,6 +74,9 @@ impl Customize { if let Some(ref v) = that.serde_derive_cfg { self.serde_derive_cfg = Some(v.clone()); } + if let Some(ref v) = that.serde_rename_all { + self.serde_rename_all = Some(v.clone()); + } if let Some(v) = that.lite_runtime { self.lite_runtime = Some(v); } @@ -120,6 +126,8 @@ impl Customize { r.serde_derive = Some(parse_bool(v)?); } else if n == "serde_derive_cfg" { r.serde_derive_cfg = Some(v.to_owned()); + } else if n == "serde_rename_all" { + r.serde_rename_all = Some(v.to_owned()); } else if n == "lite_runtime" { r.lite_runtime = Some(parse_bool(v)?); } else if n == "gen_mod_rs" { @@ -147,6 +155,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz let lite_runtime = None; let gen_mod_rs = None; let inside_protobuf = None; + let serde_rename_all = None; Customize { expose_oneof, expose_fields, @@ -155,6 +164,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, gen_mod_rs, inside_protobuf, @@ -162,6 +172,13 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz } } +pub fn customize_from_rustproto_for_enum(source: &EnumOptions) -> Customize { + let serde_rename_all = rustproto::exts::serde_rename_all.get(source); + let mut r = Customize::default(); + r.serde_rename_all = serde_rename_all; + return r; +} + pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { let expose_oneof = None; let expose_fields = rustproto::exts::expose_fields_field.get(source); @@ -169,6 +186,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { let carllerche_bytes_for_bytes = rustproto::exts::carllerche_bytes_for_bytes_field.get(source); let carllerche_bytes_for_string = rustproto::exts::carllerche_bytes_for_string_field.get(source); + let serde_rename_all = None; let serde_derive = None; let serde_derive_cfg = None; let lite_runtime = None; @@ -182,6 +200,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, gen_mod_rs, inside_protobuf, @@ -200,6 +219,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { let lite_runtime = rustproto::exts::lite_runtime_all.get(source); let gen_mod_rs = None; let inside_protobuf = None; + let serde_rename_all = None; Customize { expose_oneof, expose_fields, @@ -208,6 +228,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, inside_protobuf, gen_mod_rs, diff --git a/src/enums.rs b/src/enums.rs index c2ce241..ec3444e 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -1,17 +1,18 @@ use std::collections::HashSet; -use protobuf::descriptor::*; - -use super::code_writer::*; -use super::customize::Customize; use file_descriptor::file_descriptor_proto_expr; use inside::protobuf_crate_path; +use protobuf::descriptor::*; use protobuf_name::ProtobufAbsolutePath; use rust_types_values::type_name_to_rust_relative; use scope::EnumWithScope; use scope::RootScope; use scope::WithScope; use serde; +use CodeWriter; + +use crate::customize::customize_from_rustproto_for_enum; +use crate::Customize; #[derive(Clone)] pub struct EnumValueGen { @@ -90,11 +91,16 @@ impl<'a> EnumGen<'a> { == FileOptions_OptimizeMode::LITE_RUNTIME }); + let mut customize = customize.clone(); + customize.update_with(&customize_from_rustproto_for_enum( + enum_with_scope.en.options.as_ref().unwrap_or_default(), + )); + EnumGen { enum_with_scope, type_name: rust_name, lite_runtime, - customize: customize.clone(), + customize, } } @@ -175,6 +181,10 @@ impl<'a> EnumGen<'a> { &self.customize, "derive(::serde::Serialize, ::serde::Deserialize)", ); + if let Some(ref ren) = self.customize.serde_rename_all { + let attr = format!("serde(rename_all = \"{}\")", ren); + serde::write_serde_attr(w, &self.customize, &attr); + } let ref type_name = self.type_name; w.expr_block(&format!("pub enum {}", type_name), |w| { for value in self.values_all() { diff --git a/src/extensions.rs b/src/extensions.rs index 0740fdb..def5948 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -1,5 +1,3 @@ -use super::code_writer::CodeWriter; -use super::rust_types_values::*; use field::rust_field_name_for_protobuf_field_name; use inside::protobuf_crate_path; use protobuf::descriptor::*; @@ -7,6 +5,9 @@ use protobuf_name::ProtobufAbsolutePath; use scope::RootScope; use Customize; +use super::code_writer::CodeWriter; +use super::rust_types_values::*; + struct ExtGen<'a> { file: &'a FileDescriptorProto, root_scope: &'a RootScope<'a>, diff --git a/src/field/mod.rs b/src/field/mod.rs index 842f01f..e4be944 100644 --- a/src/field/mod.rs +++ b/src/field/mod.rs @@ -1,20 +1,14 @@ +use std::marker; + +use float; +use inside::protobuf_crate_path; +use message::RustTypeMessage; +use oneof::OneofField; use protobuf::descriptor::*; use protobuf::rt; use protobuf::rust; use protobuf::text_format; use protobuf::wire_format; - -use super::code_writer::CodeWriter; -use super::enums::*; -use super::rust_types_values::*; - -use super::customize::customize_from_rustproto_for_field; -use super::customize::Customize; -use oneof::OneofField; - -use float; -use inside::protobuf_crate_path; -use message::RustTypeMessage; use protobuf_name::ProtobufAbsolutePath; use rust_name::RustIdent; use rust_name::RustIdentWithPath; @@ -22,9 +16,14 @@ use scope::FieldWithContext; use scope::MessageOrEnumWithScope; use scope::RootScope; use scope::WithScope; -use std::marker; use syntax::Syntax; +use super::code_writer::CodeWriter; +use super::customize::customize_from_rustproto_for_field; +use super::customize::Customize; +use super::enums::*; +use super::rust_types_values::*; + fn type_is_copy(field_type: FieldDescriptorProto_Type) -> bool { match field_type { FieldDescriptorProto_Type::TYPE_MESSAGE @@ -189,7 +188,7 @@ impl<'a> RepeatedField<'a> { #[derive(Clone)] pub struct MapField<'a> { - name: String, + _name: String, key: FieldElem<'a>, value: FieldElem<'a>, } @@ -428,7 +427,7 @@ impl AccessorFn { #[derive(Clone)] pub(crate) struct FieldGen<'a> { - root_scope: &'a RootScope<'a>, + _root_scope: &'a RootScope<'a>, syntax: Syntax, pub proto_field: FieldWithContext<'a>, // field name in generated code @@ -472,7 +471,7 @@ impl<'a> FieldGen<'a> { // map field (FieldElem::Message(name, _, Some(key_value), _), true) => { FieldKind::Map(MapField { - name: name, + _name: name, key: key_value.0.clone(), value: key_value.1.clone(), }) @@ -499,7 +498,7 @@ impl<'a> FieldGen<'a> { }; FieldGen { - root_scope, + _root_scope: root_scope, syntax: field.message.get_scope().file_scope.syntax(), rust_name: field.rust_name(), proto_type: field.field.get_field_type(), @@ -1,4 +1,7 @@ -//! This crate implement protobuf codegen. +//! # Protobuf code generator +//! +//! This crate contains protobuf code generator implementation +//! and a `protoc-gen-rust` `protoc` plugin. //! //! This crate: //! * provides `protoc-gen-rust` plugin for `protoc` command @@ -8,11 +11,71 @@ //! (except for `protoc-gen-rust` binary). //! //! Code can be generated with either: -//! * `protoc-gen-rust` binary or -//! * `protoc-rust` crate (codegen which depends on `protoc` binary for parsing) -//! * `protobuf-codegen-pure` crate +//! * `protoc-gen-rust` plugin for `protoc` or +//! * [`protoc-rust`](https://docs.rs/protoc) crate +//! (code generator which depends on `protoc` binary for parsing of `.proto` files) +//! * [`protobuf-codegen-pure`](https://docs.rs/protobuf-codegen-pure) crate, +//! similar API to `protoc-rust`, but uses pure rust parser of `.proto` files. +//! +//! # `protoc-gen-rust` plugin for `protoc` +//! +//! When non-cargo build system is used, consider using standard protobuf code generation pattern: +//! `protoc` command does all the work of handling paths and parsing `.proto` files. +//! When `protoc` is invoked with `--rust_out=` option, it invokes `protoc-gen-rust` plugin. +//! provided by this crate. +//! +//! When building with cargo, consider using `protoc-rust` or `protobuf-codegen-pure` crates. +//! +//! ## How to use `protoc-gen-rust` if you have to +//! +//! (Note `protoc` can be invoked programmatically with +//! [protoc crate](https://docs.rs/protoc)) +//! +//! 0) Install protobuf for `protoc` binary. +//! +//! On OS X [Homebrew](https://github.com/Homebrew/brew) can be used: +//! +//! ```sh +//! brew install protobuf +//! ``` +//! +//! On Ubuntu, `protobuf-compiler` package can be installed: +//! +//! ```sh +//! apt-get install protobuf-compiler +//! ``` +//! +//! Protobuf is needed only for code generation, `rust-protobuf` runtime +//! does not use `protobuf` library. +//! +//! 1) Install `protoc-gen-rust` program (which is `protoc` plugin) +//! +//! It can be installed either from source or with `cargo install protobuf` command. +//! +//! 2) Add `protoc-gen-rust` to $PATH +//! +//! If you installed it with cargo, it should be +//! +//! ```sh +//! PATH="$HOME/.cargo/bin:$PATH" +//! ``` +//! +//! 3) Generate .rs files: +//! +//! ```sh +//! protoc --rust_out . foo.proto +//! ``` +//! +//! This will generate .rs files in current directory. +//! +//! # Version 2 +//! +//! This is documentation for version 2 of the crate. +//! +//! [Version 3 of the crate](https://docs.rs/protobuf-codegen/%3E=3.0.0-alpha) +//! (currently in development) encapsulates both `protoc` and pure codegens in this crate. -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #![deny(missing_docs)] extern crate protobuf; @@ -57,22 +120,21 @@ pub use customize::Customize; pub mod code_writer; -use self::code_writer::CodeWriter; -use self::enums::*; -use self::extensions::*; -use self::message::*; use inside::protobuf_crate_path; -use scope::FileScope; -use scope::RootScope; - -use crate::file::proto_path_to_rust_mod; - #[doc(hidden)] pub use protobuf_name::ProtobufAbsolutePath; #[doc(hidden)] pub use protobuf_name::ProtobufIdent; #[doc(hidden)] pub use protobuf_name::ProtobufRelativePath; +use scope::FileScope; +use scope::RootScope; + +use self::code_writer::CodeWriter; +use self::enums::*; +use self::extensions::*; +use self::message::*; +use crate::file::proto_path_to_rust_mod; fn escape_byte(s: &mut String, b: u8) { if b == b'\n' { @@ -192,7 +254,7 @@ fn gen_file( { let mut w = CodeWriter::new(&mut v); - w.write_generated_by("rust-protobuf", "2.22.1"); + w.write_generated_by("rust-protobuf", "2.27.1"); w.write_line(&format!("//! Generated file from `{}`", file.get_name())); if customize.inside_protobuf != Some(true) { w.write_line(""); diff --git a/src/message.rs b/src/message.rs index 6987ce7..fbe9ed4 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,9 +1,5 @@ -use super::code_writer::*; -use super::customize::customize_from_rustproto_for_message; -use super::customize::Customize; -use super::enums::*; -use super::field::*; -use super::rust_types_values::*; +use std::fmt; + use file_descriptor::file_descriptor_proto_expr; use inside::protobuf_crate_path; use oneof::OneofGen; @@ -15,7 +11,12 @@ use scope::RootScope; use scope::WithScope; use serde; -use std::fmt; +use super::code_writer::*; +use super::customize::customize_from_rustproto_for_message; +use super::customize::Customize; +use super::enums::*; +use super::field::*; +use super::rust_types_values::*; /// Protobuf message Rust type name #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/src/oneof.rs b/src/oneof.rs index e767709..44201ea 100644 --- a/src/oneof.rs +++ b/src/oneof.rs @@ -1,5 +1,7 @@ //! Oneof-related codegen functions. +use std::collections::HashSet; + use code_writer::CodeWriter; use field::FieldElem; use field::FieldGen; @@ -14,7 +16,6 @@ use scope::OneofWithContext; use scope::RootScope; use scope::WithScope; use serde; -use std::collections::HashSet; use Customize; // oneof one { ... } @@ -78,12 +79,12 @@ impl<'a> OneofField<'a> { #[derive(Clone)] pub(crate) struct OneofVariantGen<'a> { - oneof: &'a OneofGen<'a>, - variant: OneofVariantWithContext<'a>, + _oneof: &'a OneofGen<'a>, + _variant: OneofVariantWithContext<'a>, oneof_field: OneofField<'a>, pub field: FieldGen<'a>, path: String, - customize: Customize, + _customize: Customize, } impl<'a> OneofVariantGen<'a> { @@ -95,8 +96,8 @@ impl<'a> OneofVariantGen<'a> { customize: Customize, ) -> OneofVariantGen<'a> { OneofVariantGen { - oneof, - variant: variant.clone(), + _oneof: oneof, + _variant: variant.clone(), field: field.clone(), path: format!( "{}::{}", @@ -109,7 +110,7 @@ impl<'a> OneofVariantGen<'a> { field.oneof().elem.clone(), oneof.message.root_scope, ), - customize, + _customize: customize, } } @@ -128,7 +129,6 @@ pub(crate) struct OneofGen<'a> { message: &'a MessageGen<'a>, pub oneof: OneofWithContext<'a>, type_name: RustType, - lite_runtime: bool, customize: Customize, } @@ -143,7 +143,6 @@ impl<'a> OneofGen<'a> { message, oneof, type_name: RustType::Oneof(rust_name.to_string()), - lite_runtime: message.lite_runtime, customize: customize.clone(), } } diff --git a/src/protobuf_name.rs b/src/protobuf_name.rs index 03163e3..c40a69c 100644 --- a/src/protobuf_name.rs +++ b/src/protobuf_name.rs @@ -245,8 +245,8 @@ impl ProtobufAbsolutePath { /// From string. pub fn new(path: String) -> ProtobufAbsolutePath { - assert!(path.is_empty() || path.starts_with("."), path); - assert!(!path.ends_with("."), path); + assert!(path.is_empty() || path.starts_with("."), "{}", path); + assert!(!path.ends_with("."), "{}", path); ProtobufAbsolutePath { path } } diff --git a/src/rust_types_values.rs b/src/rust_types_values.rs index 9660062..e9b017d 100644 --- a/src/rust_types_values.rs +++ b/src/rust_types_values.rs @@ -1,6 +1,5 @@ use std::cmp; -use super::well_known_types::is_well_known_type_full; use inside::protobuf_crate_path; use message::RustTypeMessage; use protobuf::descriptor::*; @@ -11,6 +10,8 @@ use scope::WithScope; use strx::capitalize; use Customize; +use super::well_known_types::is_well_known_type_full; + // Represent subset of rust types used in generated code #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum RustType { diff --git a/src/scope.rs b/src/scope.rs index 87faf1f..5f92d08 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -1,3 +1,10 @@ +use protobuf::descriptor::DescriptorProto; +use protobuf::descriptor::EnumDescriptorProto; +use protobuf::descriptor::EnumValueDescriptorProto; +use protobuf::descriptor::FieldDescriptorProto; +use protobuf::descriptor::FileDescriptorProto; +use protobuf::descriptor::OneofDescriptorProto; + use crate::field::rust_field_name_for_protobuf_field_name; use crate::file::proto_path_to_rust_mod; use crate::protobuf_name::ProtobufAbsolutePath; @@ -7,12 +14,6 @@ use crate::rust; use crate::rust_name::RustIdent; use crate::rust_name::RustIdentWithPath; use crate::syntax::Syntax; -use protobuf::descriptor::DescriptorProto; -use protobuf::descriptor::EnumDescriptorProto; -use protobuf::descriptor::EnumValueDescriptorProto; -use protobuf::descriptor::FieldDescriptorProto; -use protobuf::descriptor::FileDescriptorProto; -use protobuf::descriptor::OneofDescriptorProto; pub(crate) struct RootScope<'a> { pub file_descriptors: &'a [FileDescriptorProto], @@ -395,7 +396,7 @@ impl<'a> EnumWithScope<'a> { .get_value() .iter() .map(|v| EnumValueWithContext { - en: self.clone(), + _en: self.clone(), proto: v, }) .collect() @@ -412,7 +413,7 @@ impl<'a> EnumWithScope<'a> { #[derive(Clone, Debug)] pub(crate) struct EnumValueWithContext<'a> { - pub en: EnumWithScope<'a>, + _en: EnumWithScope<'a>, pub proto: &'a EnumValueDescriptorProto, } |