diff --git a/Cargo.toml b/Cargo.toml index a72208a81..bf2aa5f09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,12 +36,13 @@ exclude = [ bench = false [features] -default = ["prost-derive"] +default = ["prost-derive", "std"] no-recursion-limit = [] +std = [] # When std is disabled, we provide no_std support in prost [dependencies] -bytes = "0.5" -prost-derive = { version = "0.6.1", path = "prost-derive", optional = true } +bytes = { version = "0.5", default-features = false } +prost-derive = { version = "0.6.1", path = "prost-derive", default-features = false, optional = true } [dev-dependencies] criterion = "0.3" diff --git a/conformance/Cargo.toml b/conformance/Cargo.toml index 7783eb5c5..562ffbad6 100644 --- a/conformance/Cargo.toml +++ b/conformance/Cargo.toml @@ -6,7 +6,7 @@ publish = false edition = "2018" [dependencies] -bytes = "0.5" +bytes = { version = "0.5", default-features = false } env_logger = { version = "0.7", default-features = false } log = "0.4" prost = { path = ".." } diff --git a/prost-build/Cargo.toml b/prost-build/Cargo.toml index ebc0083a7..7978ac296 100644 --- a/prost-build/Cargo.toml +++ b/prost-build/Cargo.toml @@ -10,14 +10,14 @@ description = "A Protocol Buffers implementation for the Rust Language." edition = "2018" [dependencies] -bytes = "0.5" +bytes = { version = "0.5", default-features = false } heck = "0.3" itertools = "0.8" log = "0.4" multimap = { version = "0.8", default-features = false } petgraph = { version = "0.5", default-features = false } -prost = { version = "0.6.1", path = ".." } -prost-types = { version = "0.6.1", path = "../prost-types" } +prost = { version = "0.6.1", path = "..", default-features = false } +prost-types = { version = "0.6.1", path = "../prost-types", default-features = false } tempfile = "3" [build-dependencies] diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index eaa735cf6..b042cf228 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -330,6 +330,7 @@ impl<'a> CodeGenerator<'a> { if boxed { self.buf.push_str(", boxed"); } + self.buf.push_str(", tag=\""); self.buf.push_str(&field.number().to_string()); @@ -374,12 +375,12 @@ impl<'a> CodeGenerator<'a> { self.buf.push_str(&to_snake(field.name())); self.buf.push_str(": "); if repeated { - self.buf.push_str("::std::vec::Vec<"); + self.buf.push_str("prost::alloc::vec::Vec<"); } else if optional { - self.buf.push_str("::std::option::Option<"); + self.buf.push_str("core::option::Option<"); } if boxed { - self.buf.push_str("::std::boxed::Box<"); + self.buf.push_str("prost::alloc::boxed::Box<"); } self.buf.push_str(&ty); if boxed { @@ -416,10 +417,10 @@ impl<'a> CodeGenerator<'a> { .btree_map .iter() .any(|matcher| match_ident(matcher, msg_name, Some(field.name()))); - let (annotation_ty, rust_ty) = if btree_map { - ("btree_map", "BTreeMap") + let (annotation_ty, lib_name, rust_ty) = if btree_map { + ("btree_map", "prost::alloc::collections", "BTreeMap") } else { - ("map", "HashMap") + ("map", "std::collections", "HashMap") }; let key_tag = self.field_type_tag(key); @@ -434,8 +435,9 @@ impl<'a> CodeGenerator<'a> { self.append_field_attributes(msg_name, field.name()); self.push_indent(); self.buf.push_str(&format!( - "pub {}: ::std::collections::{}<{}, {}>,\n", + "pub {}: {}::{}<{}, {}>,\n", to_snake(field.name()), + lib_name, rust_ty, key_ty, value_ty @@ -467,7 +469,7 @@ impl<'a> CodeGenerator<'a> { self.append_field_attributes(fq_message_name, oneof.name()); self.push_indent(); self.buf.push_str(&format!( - "pub {}: ::std::option::Option<{}>,\n", + "pub {}: core::option::Option<{}>,\n", to_snake(oneof.name()), name )); @@ -528,8 +530,11 @@ impl<'a> CodeGenerator<'a> { ); if boxed { - self.buf - .push_str(&format!("{}(Box<{}>),\n", to_upper_camel(field.name()), ty)); + self.buf.push_str(&format!( + "{}(prost::alloc::boxed::Box<{}>),\n", + to_upper_camel(field.name()), + ty + )); } else { self.buf .push_str(&format!("{}({}),\n", to_upper_camel(field.name()), ty)); @@ -721,8 +726,8 @@ impl<'a> CodeGenerator<'a> { Type::Int32 | Type::Sfixed32 | Type::Sint32 | Type::Enum => String::from("i32"), Type::Int64 | Type::Sfixed64 | Type::Sint64 => String::from("i64"), Type::Bool => String::from("bool"), - Type::String => String::from("std::string::String"), - Type::Bytes => String::from("std::vec::Vec"), + Type::String => String::from("prost::alloc::string::String"), + Type::Bytes => String::from("prost::alloc::vec::Vec"), Type::Group | Type::Message => self.resolve_ident(field.type_name()), } } diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index c0c572462..73a4a9c84 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -547,7 +547,10 @@ impl Config { } let buf = fs::read(descriptor_set)?; - let descriptor_set = FileDescriptorSet::decode(&*buf)?; + // Manually map error, because in no_std mode, prost::DecodeError will not implement + // Into + let descriptor_set = FileDescriptorSet::decode(&buf[..]) + .map_err(|error| Error::new(ErrorKind::InvalidData, format!("{}", error)))?; let modules = self.generate(descriptor_set.file)?; for (module, content) in modules { diff --git a/prost-derive/src/field/group.rs b/prost-derive/src/field/group.rs index 11fc237db..b72100d9f 100644 --- a/prost-derive/src/field/group.rs +++ b/prost-derive/src/field/group.rs @@ -126,7 +126,7 @@ impl Field { pub fn clear(&self, ident: TokenStream) -> TokenStream { match self.label { - Label::Optional => quote!(#ident = ::std::option::Option::None), + Label::Optional => quote!(#ident = ::core::option::Option::None), Label::Required => quote!(#ident.clear()), Label::Repeated => quote!(#ident.clear()), } diff --git a/prost-derive/src/field/map.rs b/prost-derive/src/field/map.rs index 0bb4a56e4..760ae413e 100644 --- a/prost-derive/src/field/map.rs +++ b/prost-derive/src/field/map.rs @@ -272,11 +272,11 @@ impl Field { let insert_doc = format!("Inserts a key value pair into `{}`.", ident); Some(quote! { #[doc=#get_doc] - pub fn #get(&self, key: #key_ref_ty) -> ::std::option::Option<#ty> { + pub fn #get(&self, key: #key_ref_ty) -> ::core::option::Option<#ty> { self.#ident.get(#take_ref key).cloned().and_then(#ty::from_i32) } #[doc=#insert_doc] - pub fn #insert(&mut self, key: #key_ty, value: #ty) -> ::std::option::Option<#ty> { + pub fn #insert(&mut self, key: #key_ty, value: #ty) -> ::core::option::Option<#ty> { self.#ident.insert(key, value as i32).and_then(#ty::from_i32) } }) @@ -294,12 +294,18 @@ impl Field { MapTy::HashMap => Ident::new("HashMap", Span::call_site()), MapTy::BTreeMap => Ident::new("BTreeMap", Span::call_site()), }; + // HashMap is in std, BTreeMap is in alloc (re-exported as prost::alloc) + let libname = match self.map_ty { + MapTy::HashMap => quote! { std }, + MapTy::BTreeMap => quote! { prost::alloc }, + }; + // A fake field for generating the debug wrapper let key_wrapper = fake_scalar(self.key_ty.clone()).debug(quote!(KeyWrapper)); let key = self.key_ty.rust_type(); let value_wrapper = self.value_ty.debug(); let fmt = quote! { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { #key_wrapper #value_wrapper let mut builder = f.debug_map(); @@ -313,17 +319,17 @@ impl Field { ValueTy::Scalar(ref ty) => { let value = ty.rust_type(); quote! { - struct #wrapper_name<'a>(&'a ::std::collections::#type_name<#key, #value>); - impl<'a> ::std::fmt::Debug for #wrapper_name<'a> { + struct #wrapper_name<'a>(&'a ::#libname::collections::#type_name<#key, #value>); + impl<'a> ::core::fmt::Debug for #wrapper_name<'a> { #fmt } } } ValueTy::Message => quote! { - struct #wrapper_name<'a, V: 'a>(&'a ::std::collections::#type_name<#key, V>); - impl<'a, V> ::std::fmt::Debug for #wrapper_name<'a, V> + struct #wrapper_name<'a, V: 'a>(&'a ::#libname::collections::#type_name<#key, V>); + impl<'a, V> ::core::fmt::Debug for #wrapper_name<'a, V> where - V: ::std::fmt::Debug + 'a, + V: ::core::fmt::Debug + 'a, { #fmt } diff --git a/prost-derive/src/field/message.rs b/prost-derive/src/field/message.rs index 26c034aef..4f98f473f 100644 --- a/prost-derive/src/field/message.rs +++ b/prost-derive/src/field/message.rs @@ -126,7 +126,7 @@ impl Field { pub fn clear(&self, ident: TokenStream) -> TokenStream { match self.label { - Label::Optional => quote!(#ident = ::std::option::Option::None), + Label::Optional => quote!(#ident = ::core::option::Option::None), Label::Required => quote!(#ident.clear()), Label::Repeated => quote!(#ident.clear()), } diff --git a/prost-derive/src/field/mod.rs b/prost-derive/src/field/mod.rs index 14b908ecf..df0afbd20 100644 --- a/prost-derive/src/field/mod.rs +++ b/prost-derive/src/field/mod.rs @@ -4,8 +4,8 @@ mod message; mod oneof; mod scalar; -use std::fmt; -use std::slice; +use core::fmt; +use core::slice; use anyhow::{bail, Error}; use proc_macro2::TokenStream; @@ -135,7 +135,7 @@ impl Field { pub fn default(&self) -> TokenStream { match *self { Field::Scalar(ref scalar) => scalar.default(), - _ => quote!(::std::default::Default::default()), + _ => quote!(::core::default::Default::default()), } } diff --git a/prost-derive/src/field/oneof.rs b/prost-derive/src/field/oneof.rs index db4e19076..364c1c9f7 100644 --- a/prost-derive/src/field/oneof.rs +++ b/prost-derive/src/field/oneof.rs @@ -94,6 +94,6 @@ impl Field { } pub fn clear(&self, ident: TokenStream) -> TokenStream { - quote!(#ident = ::std::option::Option::None) + quote!(#ident = ::core::option::Option::None) } } diff --git a/prost-derive/src/field/scalar.rs b/prost-derive/src/field/scalar.rs index 905c060fd..b55b2a8c1 100644 --- a/prost-derive/src/field/scalar.rs +++ b/prost-derive/src/field/scalar.rs @@ -131,7 +131,7 @@ impl Field { } } Kind::Optional(..) => quote! { - if let ::std::option::Option::Some(ref value) = #ident { + if let ::core::option::Option::Some(ref value) = #ident { #encode_fn(#tag, value, buf); } }, @@ -204,7 +204,7 @@ impl Field { _ => quote!(#ident = #default), } } - Kind::Optional(_) => quote!(#ident = ::std::option::Option::None), + Kind::Optional(_) => quote!(#ident = ::core::option::Option::None), Kind::Repeated | Kind::Packed => quote!(#ident.clear()), } } @@ -213,8 +213,8 @@ impl Field { pub fn default(&self) -> TokenStream { match self.kind { Kind::Plain(ref value) | Kind::Required(ref value) => value.owned(), - Kind::Optional(_) => quote!(::std::option::Option::None), - Kind::Repeated | Kind::Packed => quote!(::std::vec::Vec::new()), + Kind::Optional(_) => quote!(::core::option::Option::None), + Kind::Repeated | Kind::Packed => quote!(::prost::alloc::vec::Vec::new()), } } @@ -223,11 +223,11 @@ impl Field { if let Ty::Enumeration(ref ty) = self.ty { quote! { struct #wrap_name<'a>(&'a i32); - impl<'a> ::std::fmt::Debug for #wrap_name<'a> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + impl<'a> ::core::fmt::Debug for #wrap_name<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { match #ty::from_i32(*self.0) { - None => ::std::fmt::Debug::fmt(&self.0, f), - Some(en) => ::std::fmt::Debug::fmt(&en, f), + None => ::core::fmt::Debug::fmt(&self.0, f), + Some(en) => ::core::fmt::Debug::fmt(&en, f), } } } @@ -246,19 +246,19 @@ impl Field { match self.kind { Kind::Plain(_) | Kind::Required(_) => self.debug_inner(wrapper_name), Kind::Optional(_) => quote! { - struct #wrapper_name<'a>(&'a ::std::option::Option<#inner_ty>); - impl<'a> ::std::fmt::Debug for #wrapper_name<'a> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + struct #wrapper_name<'a>(&'a ::core::option::Option<#inner_ty>); + impl<'a> ::core::fmt::Debug for #wrapper_name<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { #wrapper - ::std::fmt::Debug::fmt(&self.0.as_ref().map(Inner), f) + ::core::fmt::Debug::fmt(&self.0.as_ref().map(Inner), f) } } }, Kind::Repeated | Kind::Packed => { quote! { - struct #wrapper_name<'a>(&'a ::std::vec::Vec<#inner_ty>); - impl<'a> ::std::fmt::Debug for #wrapper_name<'a> { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + struct #wrapper_name<'a>(&'a ::prost::alloc::vec::Vec<#inner_ty>); + impl<'a> ::core::fmt::Debug for #wrapper_name<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { let mut vec_builder = f.debug_list(); for v in self.0 { #wrapper @@ -315,7 +315,7 @@ impl Field { #[doc=#set_doc] pub fn #set(&mut self, value: #ty) { - self.#ident = ::std::option::Option::Some(value as i32); + self.#ident = ::core::option::Option::Some(value as i32); } } } @@ -328,9 +328,9 @@ impl Field { let push_doc = format!("Appends the provided enum value to `{}`.", ident_str); quote! { #[doc=#iter_doc] - pub fn #ident(&self) -> ::std::iter::FilterMap< - ::std::iter::Cloned<::std::slice::Iter>, - fn(i32) -> ::std::option::Option<#ty>, + pub fn #ident(&self) -> ::core::iter::FilterMap< + ::core::iter::Cloned<::core::slice::Iter>, + fn(i32) -> ::core::option::Option<#ty>, > { self.#ident.iter().cloned().filter_map(#ty::from_i32) } @@ -345,9 +345,9 @@ impl Field { let ty = self.ty.rust_ref_type(); let match_some = if self.ty.is_numeric() { - quote!(::std::option::Option::Some(val) => val,) + quote!(::core::option::Option::Some(val) => val,) } else { - quote!(::std::option::Option::Some(ref val) => &val[..],) + quote!(::core::option::Option::Some(ref val) => &val[..],) }; let get_doc = format!( @@ -360,7 +360,7 @@ impl Field { pub fn #ident(&self) -> #ty { match self.#ident { #match_some - ::std::option::Option::None => #default, + ::core::option::Option::None => #default, } } }) @@ -497,8 +497,8 @@ impl Ty { // TODO: rename to 'owned_type'. pub fn rust_type(&self) -> TokenStream { match *self { - Ty::String => quote!(::std::string::String), - Ty::Bytes => quote!(::std::vec::Vec), + Ty::String => quote!(::prost::alloc::string::String), + Ty::Bytes => quote!(::prost::alloc::vec::Vec), _ => self.rust_ref_type(), } } @@ -643,16 +643,16 @@ impl DefaultValue { match value { "inf" => { return Ok(DefaultValue::Path(parse_str::( - "::std::f32::INFINITY", + "::core::f32::INFINITY", )?)); } "-inf" => { return Ok(DefaultValue::Path(parse_str::( - "::std::f32::NEG_INFINITY", + "::core::f32::NEG_INFINITY", )?)); } "nan" => { - return Ok(DefaultValue::Path(parse_str::("::std::f32::NAN")?)); + return Ok(DefaultValue::Path(parse_str::("::core::f32::NAN")?)); } _ => (), } @@ -661,16 +661,16 @@ impl DefaultValue { match value { "inf" => { return Ok(DefaultValue::Path(parse_str::( - "::std::f64::INFINITY", + "::core::f64::INFINITY", )?)); } "-inf" => { return Ok(DefaultValue::Path(parse_str::( - "::std::f64::NEG_INFINITY", + "::core::f64::NEG_INFINITY", )?)); } "nan" => { - return Ok(DefaultValue::Path(parse_str::("::std::f64::NAN")?)); + return Ok(DefaultValue::Path(parse_str::("::core::f64::NAN")?)); } _ => (), } @@ -750,10 +750,12 @@ impl DefaultValue { pub fn owned(&self) -> TokenStream { match *self { DefaultValue::String(ref value) if value.is_empty() => { - quote!(::std::string::String::new()) + quote!(::prost::alloc::string::String::new()) } DefaultValue::String(ref value) => quote!(#value.to_owned()), - DefaultValue::Bytes(ref value) if value.is_empty() => quote!(::std::vec::Vec::new()), + DefaultValue::Bytes(ref value) if value.is_empty() => { + quote!(::prost::alloc::vec::Vec::new()) + } DefaultValue::Bytes(ref value) => { let lit = LitByteStr::new(value, Span::call_site()); quote!(#lit.to_owned()) diff --git a/prost-derive/src/lib.rs b/prost-derive/src/lib.rs index c3596212a..2809e8ce6 100644 --- a/prost-derive/src/lib.rs +++ b/prost-derive/src/lib.rs @@ -189,7 +189,7 @@ fn try_message(input: TokenStream) -> Result { wire_type: ::prost::encoding::WireType, buf: &mut B, ctx: ::prost::encoding::DecodeContext, - ) -> ::std::result::Result<(), ::prost::DecodeError> + ) -> ::core::result::Result<(), ::prost::DecodeError> where B: ::prost::bytes::Buf { #struct_name match tag { @@ -216,8 +216,8 @@ fn try_message(input: TokenStream) -> Result { } } - impl ::std::fmt::Debug for #ident { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + impl ::core::fmt::Debug for #ident { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { let mut builder = #debug_builder; #(#debugs;)* builder.finish() @@ -281,7 +281,7 @@ fn try_enumeration(input: TokenStream) -> Result { .iter() .map(|&(_, ref value)| quote!(#value => true)); let from = variants.iter().map( - |&(ref variant, ref value)| quote!(#value => ::std::option::Option::Some(#ident::#variant)), + |&(ref variant, ref value)| quote!(#value => ::core::option::Option::Some(#ident::#variant)), ); let is_valid_doc = format!("Returns `true` if `value` is a variant of `{}`.", ident); @@ -301,21 +301,21 @@ fn try_enumeration(input: TokenStream) -> Result { } #[doc=#from_i32_doc] - pub fn from_i32(value: i32) -> ::std::option::Option<#ident> { + pub fn from_i32(value: i32) -> ::core::option::Option<#ident> { match value { #(#from,)* - _ => ::std::option::Option::None, + _ => ::core::option::Option::None, } } } - impl ::std::default::Default for #ident { + impl ::core::default::Default for #ident { fn default() -> #ident { #ident::#default } } - impl ::std::convert::From<#ident> for i32 { + impl ::core::convert::From<#ident> for i32 { fn from(value: #ident) -> i32 { value as i32 } @@ -400,13 +400,13 @@ fn try_oneof(input: TokenStream) -> Result { quote! { #tag => { match field { - ::std::option::Option::Some(#ident::#variant_ident(ref mut value)) => { + ::core::option::Option::Some(#ident::#variant_ident(ref mut value)) => { #merge }, _ => { - let mut owned_value = ::std::default::Default::default(); + let mut owned_value = ::core::default::Default::default(); let value = &mut owned_value; - #merge.map(|_| *field = ::std::option::Option::Some(#ident::#variant_ident(owned_value))) + #merge.map(|_| *field = ::core::option::Option::Some(#ident::#variant_ident(owned_value))) }, } } @@ -437,12 +437,12 @@ fn try_oneof(input: TokenStream) -> Result { } pub fn merge( - field: &mut ::std::option::Option<#ident>, + field: &mut ::core::option::Option<#ident>, tag: u32, wire_type: ::prost::encoding::WireType, buf: &mut B, ctx: ::prost::encoding::DecodeContext, - ) -> ::std::result::Result<(), ::prost::DecodeError> + ) -> ::core::result::Result<(), ::prost::DecodeError> where B: ::prost::bytes::Buf { match tag { #(#merge,)* @@ -458,8 +458,8 @@ fn try_oneof(input: TokenStream) -> Result { } } - impl ::std::fmt::Debug for #ident { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + impl ::core::fmt::Debug for #ident { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { match *self { #(#debug,)* } diff --git a/prost-types/Cargo.toml b/prost-types/Cargo.toml index 59de64452..7a8112f3a 100644 --- a/prost-types/Cargo.toml +++ b/prost-types/Cargo.toml @@ -13,6 +13,10 @@ edition = "2018" doctest = false test = false +[features] +default = ["std"] +std = ["prost/std"] + [dependencies] -bytes = "0.5" -prost = { version = "0.6.1", path = ".." } +bytes = { version = "0.5", default-features = false } +prost = { version = "0.6.1", path = "..", default-features = false } diff --git a/prost-types/src/compiler.rs b/prost-types/src/compiler.rs index 421bd78ba..ebae62473 100644 --- a/prost-types/src/compiler.rs +++ b/prost-types/src/compiler.rs @@ -2,15 +2,15 @@ #[derive(Clone, PartialEq, ::prost::Message)] pub struct Version { #[prost(int32, optional, tag="1")] - pub major: ::std::option::Option, + pub major: core::option::Option, #[prost(int32, optional, tag="2")] - pub minor: ::std::option::Option, + pub minor: core::option::Option, #[prost(int32, optional, tag="3")] - pub patch: ::std::option::Option, + pub patch: core::option::Option, /// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should /// be empty for mainline stable releases. #[prost(string, optional, tag="4")] - pub suffix: ::std::option::Option, + pub suffix: core::option::Option, } /// An encoded CodeGeneratorRequest is written to the plugin's stdin. #[derive(Clone, PartialEq, ::prost::Message)] @@ -19,10 +19,10 @@ pub struct CodeGeneratorRequest { /// code generator should generate code only for these files. Each file's /// descriptor will be included in proto_file, below. #[prost(string, repeated, tag="1")] - pub file_to_generate: ::std::vec::Vec, + pub file_to_generate: prost::alloc::vec::Vec, /// The generator parameter passed on the command-line. #[prost(string, optional, tag="2")] - pub parameter: ::std::option::Option, + pub parameter: core::option::Option, /// FileDescriptorProtos for all files in files_to_generate and everything /// they import. The files will appear in topological order, so each file /// appears before any file that imports it. @@ -38,10 +38,10 @@ pub struct CodeGeneratorRequest { /// Type names of fields and extensions in the FileDescriptorProto are always /// fully qualified. #[prost(message, repeated, tag="15")] - pub proto_file: ::std::vec::Vec, + pub proto_file: prost::alloc::vec::Vec, /// The version number of protocol compiler. #[prost(message, optional, tag="3")] - pub compiler_version: ::std::option::Option, + pub compiler_version: core::option::Option, } /// The plugin writes an encoded CodeGeneratorResponse to stdout. #[derive(Clone, PartialEq, ::prost::Message)] @@ -55,9 +55,9 @@ pub struct CodeGeneratorResponse { /// unparseable -- should be reported by writing a message to stderr and /// exiting with a non-zero status code. #[prost(string, optional, tag="1")] - pub error: ::std::option::Option, + pub error: core::option::Option, #[prost(message, repeated, tag="15")] - pub file: ::std::vec::Vec, + pub file: prost::alloc::vec::Vec, } pub mod code_generator_response { /// Represents a single generated file. @@ -75,7 +75,7 @@ pub mod code_generator_response { /// this writing protoc does not optimize for this -- it will read the entire /// CodeGeneratorResponse before writing files to disk. #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, /// If non-empty, indicates that the named file should already exist, and the /// content here is to be inserted into that file at a defined insertion /// point. This feature allows a code generator to extend the output @@ -114,9 +114,9 @@ pub mod code_generator_response { /// /// If |insertion_point| is present, |name| must also be present. #[prost(string, optional, tag="2")] - pub insertion_point: ::std::option::Option, + pub insertion_point: core::option::Option, /// The file contents. #[prost(string, optional, tag="15")] - pub content: ::std::option::Option, + pub content: core::option::Option, } } diff --git a/prost-types/src/lib.rs b/prost-types/src/lib.rs index 26013c5c9..38858fbbe 100644 --- a/prost-types/src/lib.rs +++ b/prost-types/src/lib.rs @@ -9,10 +9,11 @@ //! //! [1]: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf -use std::convert::TryFrom; -use std::i32; -use std::i64; -use std::time; +#![no_std] +extern crate alloc; + +use core::i32; +use core::i64; include!("protobuf.rs"); pub mod compiler { @@ -23,131 +24,140 @@ pub mod compiler { // because the Protobuf versions are signed. To make them easier to work with, `From` conversions // are defined in both directions. -const NANOS_PER_SECOND: i32 = 1_000_000_000; - -impl Duration { - /// Normalizes the duration to a canonical format. - /// - /// Based on [`google::protobuf::util::CreateNormalized`][1]. - /// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L79-L100 - fn normalize(&mut self) { - // Make sure nanos is in the range. - if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { - self.seconds += (self.nanos / NANOS_PER_SECOND) as i64; - self.nanos %= NANOS_PER_SECOND; +#[cfg(feature = "std")] +mod std_conversions { + use super::*; + extern crate std; + + use std::time; + use core::convert::TryFrom; + + const NANOS_PER_SECOND: i32 = 1_000_000_000; + + impl Duration { + /// Normalizes the duration to a canonical format. + /// + /// Based on [`google::protobuf::util::CreateNormalized`][1]. + /// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L79-L100 + fn normalize(&mut self) { + // Make sure nanos is in the range. + if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { + self.seconds += (self.nanos / NANOS_PER_SECOND) as i64; + self.nanos %= NANOS_PER_SECOND; + } + + // nanos should have the same sign as seconds. + if self.seconds < 0 && self.nanos > 0 { + self.seconds += 1; + self.nanos -= NANOS_PER_SECOND; + } else if self.seconds > 0 && self.nanos < 0 { + self.seconds -= 1; + self.nanos += NANOS_PER_SECOND; + } + // TODO: should this be checked? + // debug_assert!(self.seconds >= -315_576_000_000 && self.seconds <= 315_576_000_000, + // "invalid duration: {:?}", self); } + } - // nanos should have the same sign as seconds. - if self.seconds < 0 && self.nanos > 0 { - self.seconds += 1; - self.nanos -= NANOS_PER_SECOND; - } else if self.seconds > 0 && self.nanos < 0 { - self.seconds -= 1; - self.nanos += NANOS_PER_SECOND; + /// Converts a `std::time::Duration` to a `Duration`. + impl From for Duration { + fn from(duration: time::Duration) -> Duration { + let seconds = duration.as_secs(); + let seconds = if seconds > i64::MAX as u64 { + i64::MAX + } else { + seconds as i64 + }; + let nanos = duration.subsec_nanos(); + let nanos = if nanos > i32::MAX as u32 { + i32::MAX + } else { + nanos as i32 + }; + let mut duration = Duration { seconds, nanos }; + duration.normalize(); + duration } - // TODO: should this be checked? - // debug_assert!(self.seconds >= -315_576_000_000 && self.seconds <= 315_576_000_000, - // "invalid duration: {:?}", self); } -} -/// Converts a `std::time::Duration` to a `Duration`. -impl From for Duration { - fn from(duration: time::Duration) -> Duration { - let seconds = duration.as_secs(); - let seconds = if seconds > i64::MAX as u64 { - i64::MAX - } else { - seconds as i64 - }; - let nanos = duration.subsec_nanos(); - let nanos = if nanos > i32::MAX as u32 { - i32::MAX - } else { - nanos as i32 - }; - let mut duration = Duration { seconds, nanos }; - duration.normalize(); - duration - } -} + impl TryFrom for time::Duration { + type Error = time::Duration; -impl TryFrom for time::Duration { - type Error = time::Duration; - - /// Converts a `Duration` to a result containing a positive (`Ok`) or negative (`Err`) - /// `std::time::Duration`. - fn try_from(mut duration: Duration) -> Result { - duration.normalize(); - if duration.seconds >= 0 { - Ok(time::Duration::new( - duration.seconds as u64, - duration.nanos as u32, - )) - } else { - Err(time::Duration::new( - (-duration.seconds) as u64, - (-duration.nanos) as u32, - )) + /// Converts a `Duration` to a result containing a positive (`Ok`) or negative (`Err`) + /// `std::time::Duration`. + fn try_from(mut duration: Duration) -> Result { + duration.normalize(); + if duration.seconds >= 0 { + Ok(time::Duration::new( + duration.seconds as u64, + duration.nanos as u32, + )) + } else { + Err(time::Duration::new( + (-duration.seconds) as u64, + (-duration.nanos) as u32, + )) + } } } -} - -impl Timestamp { - /// Normalizes the timestamp to a canonical format. - /// - /// Based on [`google::protobuf::util::CreateNormalized`][1]. - /// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L59-L77 - fn normalize(&mut self) { - // Make sure nanos is in the range. - if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { - self.seconds += (self.nanos / NANOS_PER_SECOND) as i64; - self.nanos %= NANOS_PER_SECOND; - } - // For Timestamp nanos should be in the range [0, 999999999]. - if self.nanos < 0 { - self.seconds -= 1; - self.nanos += NANOS_PER_SECOND; + impl Timestamp { + /// Normalizes the timestamp to a canonical format. + /// + /// Based on [`google::protobuf::util::CreateNormalized`][1]. + /// [1]: https://github.com/google/protobuf/blob/v3.3.2/src/google/protobuf/util/time_util.cc#L59-L77 + fn normalize(&mut self) { + // Make sure nanos is in the range. + if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { + self.seconds += (self.nanos / NANOS_PER_SECOND) as i64; + self.nanos %= NANOS_PER_SECOND; + } + + // For Timestamp nanos should be in the range [0, 999999999]. + if self.nanos < 0 { + self.seconds -= 1; + self.nanos += NANOS_PER_SECOND; + } + + // TODO: should this be checked? + // debug_assert!(self.seconds >= -62_135_596_800 && self.seconds <= 253_402_300_799, + // "invalid timestamp: {:?}", self); } - - // TODO: should this be checked? - // debug_assert!(self.seconds >= -62_135_596_800 && self.seconds <= 253_402_300_799, - // "invalid timestamp: {:?}", self); } -} -/// Converts a `std::time::SystemTime` to a `Timestamp`. -impl From for Timestamp { - fn from(time: time::SystemTime) -> Timestamp { - let duration = Duration::from(time.duration_since(time::UNIX_EPOCH).unwrap()); - Timestamp { - seconds: duration.seconds, - nanos: duration.nanos, + /// Converts a `std::time::SystemTime` to a `Timestamp`. + impl From for Timestamp { + fn from(time: time::SystemTime) -> Timestamp { + let duration = Duration::from(time.duration_since(time::UNIX_EPOCH).unwrap()); + Timestamp { + seconds: duration.seconds, + nanos: duration.nanos, + } } } -} -impl TryFrom for time::SystemTime { - type Error = time::Duration; - - /// Converts a `Timestamp` to a `SystemTime`, or if the timestamp falls before the Unix epoch, - /// a duration containing the difference. - fn try_from(mut timestamp: Timestamp) -> Result { - timestamp.normalize(); - if timestamp.seconds >= 0 { - Ok(time::UNIX_EPOCH - + time::Duration::new(timestamp.seconds as u64, timestamp.nanos as u32)) - } else { - let mut duration = Duration { - seconds: -timestamp.seconds, - nanos: timestamp.nanos, - }; - duration.normalize(); - Err(time::Duration::new( - duration.seconds as u64, - duration.nanos as u32, - )) + impl TryFrom for time::SystemTime { + type Error = time::Duration; + + /// Converts a `Timestamp` to a `SystemTime`, or if the timestamp falls before the Unix epoch, + /// a duration containing the difference. + fn try_from(mut timestamp: Timestamp) -> Result { + timestamp.normalize(); + if timestamp.seconds >= 0 { + Ok(time::UNIX_EPOCH + + time::Duration::new(timestamp.seconds as u64, timestamp.nanos as u32)) + } else { + let mut duration = Duration { + seconds: -timestamp.seconds, + nanos: timestamp.nanos, + }; + duration.normalize(); + Err(time::Duration::new( + duration.seconds as u64, + duration.nanos as u32, + )) + } } } } diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs index 1ffde4381..c18b3e836 100644 --- a/prost-types/src/protobuf.rs +++ b/prost-types/src/protobuf.rs @@ -3,86 +3,86 @@ #[derive(Clone, PartialEq, ::prost::Message)] pub struct FileDescriptorSet { #[prost(message, repeated, tag="1")] - pub file: ::std::vec::Vec, + pub file: prost::alloc::vec::Vec, } /// Describes a complete .proto file. #[derive(Clone, PartialEq, ::prost::Message)] pub struct FileDescriptorProto { /// file name, relative to root of source tree #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, /// e.g. "foo", "foo.bar", etc. #[prost(string, optional, tag="2")] - pub package: ::std::option::Option, + pub package: core::option::Option, /// Names of files imported by this file. #[prost(string, repeated, tag="3")] - pub dependency: ::std::vec::Vec, + pub dependency: prost::alloc::vec::Vec, /// Indexes of the public imported files in the dependency list above. #[prost(int32, repeated, packed="false", tag="10")] - pub public_dependency: ::std::vec::Vec, + pub public_dependency: prost::alloc::vec::Vec, /// Indexes of the weak imported files in the dependency list. /// For Google-internal migration only. Do not use. #[prost(int32, repeated, packed="false", tag="11")] - pub weak_dependency: ::std::vec::Vec, + pub weak_dependency: prost::alloc::vec::Vec, /// All top-level definitions in this file. #[prost(message, repeated, tag="4")] - pub message_type: ::std::vec::Vec, + pub message_type: prost::alloc::vec::Vec, #[prost(message, repeated, tag="5")] - pub enum_type: ::std::vec::Vec, + pub enum_type: prost::alloc::vec::Vec, #[prost(message, repeated, tag="6")] - pub service: ::std::vec::Vec, + pub service: prost::alloc::vec::Vec, #[prost(message, repeated, tag="7")] - pub extension: ::std::vec::Vec, + pub extension: prost::alloc::vec::Vec, #[prost(message, optional, tag="8")] - pub options: ::std::option::Option, + pub options: core::option::Option, /// This field contains optional information about the original source code. /// You may safely remove this entire field without harming runtime /// functionality of the descriptors -- the information is needed only by /// development tools. #[prost(message, optional, tag="9")] - pub source_code_info: ::std::option::Option, + pub source_code_info: core::option::Option, /// The syntax of the proto file. /// The supported values are "proto2" and "proto3". #[prost(string, optional, tag="12")] - pub syntax: ::std::option::Option, + pub syntax: core::option::Option, } /// Describes a message type. #[derive(Clone, PartialEq, ::prost::Message)] pub struct DescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(message, repeated, tag="2")] - pub field: ::std::vec::Vec, + pub field: prost::alloc::vec::Vec, #[prost(message, repeated, tag="6")] - pub extension: ::std::vec::Vec, + pub extension: prost::alloc::vec::Vec, #[prost(message, repeated, tag="3")] - pub nested_type: ::std::vec::Vec, + pub nested_type: prost::alloc::vec::Vec, #[prost(message, repeated, tag="4")] - pub enum_type: ::std::vec::Vec, + pub enum_type: prost::alloc::vec::Vec, #[prost(message, repeated, tag="5")] - pub extension_range: ::std::vec::Vec, + pub extension_range: prost::alloc::vec::Vec, #[prost(message, repeated, tag="8")] - pub oneof_decl: ::std::vec::Vec, + pub oneof_decl: prost::alloc::vec::Vec, #[prost(message, optional, tag="7")] - pub options: ::std::option::Option, + pub options: core::option::Option, #[prost(message, repeated, tag="9")] - pub reserved_range: ::std::vec::Vec, + pub reserved_range: prost::alloc::vec::Vec, /// Reserved field names, which may not be used by fields in the same message. /// A given name may only be reserved once. #[prost(string, repeated, tag="10")] - pub reserved_name: ::std::vec::Vec, + pub reserved_name: prost::alloc::vec::Vec, } pub mod descriptor_proto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct ExtensionRange { /// Inclusive. #[prost(int32, optional, tag="1")] - pub start: ::std::option::Option, + pub start: core::option::Option, /// Exclusive. #[prost(int32, optional, tag="2")] - pub end: ::std::option::Option, + pub end: core::option::Option, #[prost(message, optional, tag="3")] - pub options: ::std::option::Option, + pub options: core::option::Option, } /// Range of reserved tag numbers. Reserved tag numbers may not be used by /// fields or extension ranges in the same message. Reserved ranges may @@ -91,61 +91,61 @@ pub mod descriptor_proto { pub struct ReservedRange { /// Inclusive. #[prost(int32, optional, tag="1")] - pub start: ::std::option::Option, + pub start: core::option::Option, /// Exclusive. #[prost(int32, optional, tag="2")] - pub end: ::std::option::Option, + pub end: core::option::Option, } } #[derive(Clone, PartialEq, ::prost::Message)] pub struct ExtensionRangeOptions { /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } /// Describes a field within a message. #[derive(Clone, PartialEq, ::prost::Message)] pub struct FieldDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(int32, optional, tag="3")] - pub number: ::std::option::Option, + pub number: core::option::Option, #[prost(enumeration="field_descriptor_proto::Label", optional, tag="4")] - pub label: ::std::option::Option, + pub label: core::option::Option, /// If type_name is set, this need not be set. If both this and type_name /// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. #[prost(enumeration="field_descriptor_proto::Type", optional, tag="5")] - pub r#type: ::std::option::Option, + pub r#type: core::option::Option, /// For message and enum types, this is the name of the type. If the name /// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping /// rules are used to find the type (i.e. first the nested types within this /// message are searched, then within the parent, on up to the root /// namespace). #[prost(string, optional, tag="6")] - pub type_name: ::std::option::Option, + pub type_name: core::option::Option, /// For extensions, this is the name of the type being extended. It is /// resolved in the same manner as type_name. #[prost(string, optional, tag="2")] - pub extendee: ::std::option::Option, + pub extendee: core::option::Option, /// For numeric types, contains the original text representation of the value. /// For booleans, "true" or "false". /// For strings, contains the default text contents (not escaped in any way). /// For bytes, contains the C escaped value. All bytes >= 128 are escaped. /// TODO(kenton): Base-64 encode? #[prost(string, optional, tag="7")] - pub default_value: ::std::option::Option, + pub default_value: core::option::Option, /// If set, gives the index of a oneof in the containing type's oneof_decl /// list. This field is a member of that oneof. #[prost(int32, optional, tag="9")] - pub oneof_index: ::std::option::Option, + pub oneof_index: core::option::Option, /// JSON name of this field. The value is set by protocol compiler. If the /// user has set a "json_name" option on this field, that option's value /// will be used. Otherwise, it's deduced from the field's name by converting /// it to camelCase. #[prost(string, optional, tag="10")] - pub json_name: ::std::option::Option, + pub json_name: core::option::Option, #[prost(message, optional, tag="8")] - pub options: ::std::option::Option, + pub options: core::option::Option, } pub mod field_descriptor_proto { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] @@ -197,28 +197,28 @@ pub mod field_descriptor_proto { #[derive(Clone, PartialEq, ::prost::Message)] pub struct OneofDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(message, optional, tag="2")] - pub options: ::std::option::Option, + pub options: core::option::Option, } /// Describes an enum type. #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(message, repeated, tag="2")] - pub value: ::std::vec::Vec, + pub value: prost::alloc::vec::Vec, #[prost(message, optional, tag="3")] - pub options: ::std::option::Option, + pub options: core::option::Option, /// Range of reserved numeric values. Reserved numeric values may not be used /// by enum values in the same enum declaration. Reserved ranges may not /// overlap. #[prost(message, repeated, tag="4")] - pub reserved_range: ::std::vec::Vec, + pub reserved_range: prost::alloc::vec::Vec, /// Reserved enum value names, which may not be reused. A given name may only /// be reserved once. #[prost(string, repeated, tag="5")] - pub reserved_name: ::std::vec::Vec, + pub reserved_name: prost::alloc::vec::Vec, } pub mod enum_descriptor_proto { /// Range of reserved numeric values. Reserved values may not be used by @@ -231,51 +231,51 @@ pub mod enum_descriptor_proto { pub struct EnumReservedRange { /// Inclusive. #[prost(int32, optional, tag="1")] - pub start: ::std::option::Option, + pub start: core::option::Option, /// Inclusive. #[prost(int32, optional, tag="2")] - pub end: ::std::option::Option, + pub end: core::option::Option, } } /// Describes a value within an enum. #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumValueDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(int32, optional, tag="2")] - pub number: ::std::option::Option, + pub number: core::option::Option, #[prost(message, optional, tag="3")] - pub options: ::std::option::Option, + pub options: core::option::Option, } /// Describes a service. #[derive(Clone, PartialEq, ::prost::Message)] pub struct ServiceDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, #[prost(message, repeated, tag="2")] - pub method: ::std::vec::Vec, + pub method: prost::alloc::vec::Vec, #[prost(message, optional, tag="3")] - pub options: ::std::option::Option, + pub options: core::option::Option, } /// Describes a method of a service. #[derive(Clone, PartialEq, ::prost::Message)] pub struct MethodDescriptorProto { #[prost(string, optional, tag="1")] - pub name: ::std::option::Option, + pub name: core::option::Option, /// Input and output type names. These are resolved in the same way as /// FieldDescriptorProto.type_name, but must refer to a message type. #[prost(string, optional, tag="2")] - pub input_type: ::std::option::Option, + pub input_type: core::option::Option, #[prost(string, optional, tag="3")] - pub output_type: ::std::option::Option, + pub output_type: core::option::Option, #[prost(message, optional, tag="4")] - pub options: ::std::option::Option, + pub options: core::option::Option, /// Identifies if client streams multiple client messages #[prost(bool, optional, tag="5", default="false")] - pub client_streaming: ::std::option::Option, + pub client_streaming: core::option::Option, /// Identifies if server streams multiple server messages #[prost(bool, optional, tag="6", default="false")] - pub server_streaming: ::std::option::Option, + pub server_streaming: core::option::Option, } // =================================================================== // Options @@ -316,14 +316,14 @@ pub struct FileOptions { /// inappropriate because proto packages do not normally start with backwards /// domain names. #[prost(string, optional, tag="1")] - pub java_package: ::std::option::Option, + pub java_package: core::option::Option, /// If set, all the classes from the .proto file are wrapped in a single /// outer class with the given name. This applies to both Proto1 /// (equivalent to the old "--one_java_file" option) and Proto2 (where /// a .proto always translates to a single class, but you may want to /// explicitly choose the class name). #[prost(string, optional, tag="8")] - pub java_outer_classname: ::std::option::Option, + pub java_outer_classname: core::option::Option, /// If set true, then the Java code generator will generate a separate .java /// file for each top-level message, enum, and service defined in the .proto /// file. Thus, these types will *not* be nested inside the outer class @@ -331,11 +331,11 @@ pub struct FileOptions { /// generated to contain the file's getDescriptor() method as well as any /// top-level extensions defined in the file. #[prost(bool, optional, tag="10", default="false")] - pub java_multiple_files: ::std::option::Option, + pub java_multiple_files: core::option::Option, /// This option does nothing. #[deprecated] #[prost(bool, optional, tag="20")] - pub java_generate_equals_and_hash: ::std::option::Option, + pub java_generate_equals_and_hash: core::option::Option, /// If set true, then the Java2 code generator will generate code that /// throws an exception whenever an attempt is made to assign a non-UTF-8 /// byte sequence to a string field. @@ -343,16 +343,16 @@ pub struct FileOptions { /// However, an extension field still accepts non-UTF-8 byte sequences. /// This option has no effect on when used with the lite runtime. #[prost(bool, optional, tag="27", default="false")] - pub java_string_check_utf8: ::std::option::Option, + pub java_string_check_utf8: core::option::Option, #[prost(enumeration="file_options::OptimizeMode", optional, tag="9", default="Speed")] - pub optimize_for: ::std::option::Option, + pub optimize_for: core::option::Option, /// Sets the Go package where structs generated from this .proto will be /// placed. If omitted, the Go package will be derived from the following: /// - The basename of the package import path, if provided. /// - Otherwise, the package statement in the .proto file, if present. /// - Otherwise, the basename of the .proto file, without extension. #[prost(string, optional, tag="11")] - pub go_package: ::std::option::Option, + pub go_package: core::option::Option, /// Should generic services be generated in each language? "Generic" services /// are not specific to any particular RPC system. They are generated by the /// main code generators in each language (without additional plugins). @@ -364,59 +364,59 @@ pub struct FileOptions { /// these default to false. Old code which depends on generic services should /// explicitly set them to true. #[prost(bool, optional, tag="16", default="false")] - pub cc_generic_services: ::std::option::Option, + pub cc_generic_services: core::option::Option, #[prost(bool, optional, tag="17", default="false")] - pub java_generic_services: ::std::option::Option, + pub java_generic_services: core::option::Option, #[prost(bool, optional, tag="18", default="false")] - pub py_generic_services: ::std::option::Option, + pub py_generic_services: core::option::Option, #[prost(bool, optional, tag="42", default="false")] - pub php_generic_services: ::std::option::Option, + pub php_generic_services: core::option::Option, /// Is this file deprecated? /// Depending on the target platform, this can emit Deprecated annotations /// for everything in the file, or it will be completely ignored; in the very /// least, this is a formalization for deprecating files. #[prost(bool, optional, tag="23", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// Enables the use of arenas for the proto messages in this file. This applies /// only to generated classes for C++. #[prost(bool, optional, tag="31", default="false")] - pub cc_enable_arenas: ::std::option::Option, + pub cc_enable_arenas: core::option::Option, /// Sets the objective c class prefix which is prepended to all objective c /// generated classes from this .proto. There is no default. #[prost(string, optional, tag="36")] - pub objc_class_prefix: ::std::option::Option, + pub objc_class_prefix: core::option::Option, /// Namespace for generated classes; defaults to the package. #[prost(string, optional, tag="37")] - pub csharp_namespace: ::std::option::Option, + pub csharp_namespace: core::option::Option, /// By default Swift generators will take the proto package and CamelCase it /// replacing '.' with underscore and use that to prefix the types/symbols /// defined. When this options is provided, they will use this value instead /// to prefix the types/symbols defined. #[prost(string, optional, tag="39")] - pub swift_prefix: ::std::option::Option, + pub swift_prefix: core::option::Option, /// Sets the php class prefix which is prepended to all php generated classes /// from this .proto. Default is empty. #[prost(string, optional, tag="40")] - pub php_class_prefix: ::std::option::Option, + pub php_class_prefix: core::option::Option, /// Use this option to change the namespace of php generated classes. Default /// is empty. When this option is empty, the package name will be used for /// determining the namespace. #[prost(string, optional, tag="41")] - pub php_namespace: ::std::option::Option, + pub php_namespace: core::option::Option, /// Use this option to change the namespace of php generated metadata classes. /// Default is empty. When this option is empty, the proto file name will be /// used for determining the namespace. #[prost(string, optional, tag="44")] - pub php_metadata_namespace: ::std::option::Option, + pub php_metadata_namespace: core::option::Option, /// Use this option to change the package of ruby generated classes. Default /// is empty. When this option is not set, the package name will be used for /// determining the ruby package. #[prost(string, optional, tag="45")] - pub ruby_package: ::std::option::Option, + pub ruby_package: core::option::Option, /// The parser stores options it doesn't recognize here. /// See the documentation for the "Options" section above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } pub mod file_options { /// Generated classes can be optimized for speed or code size. @@ -454,18 +454,18 @@ pub struct MessageOptions { /// Because this is an option, the above two restrictions are not enforced by /// the protocol compiler. #[prost(bool, optional, tag="1", default="false")] - pub message_set_wire_format: ::std::option::Option, + pub message_set_wire_format: core::option::Option, /// Disables the generation of the standard "descriptor()" accessor, which can /// conflict with a field of the same name. This is meant to make migration /// from proto1 easier; new code should avoid fields named "descriptor". #[prost(bool, optional, tag="2", default="false")] - pub no_standard_descriptor_accessor: ::std::option::Option, + pub no_standard_descriptor_accessor: core::option::Option, /// Is this message deprecated? /// Depending on the target platform, this can emit Deprecated annotations /// for the message, or it will be completely ignored; in the very least, /// this is a formalization for deprecating messages. #[prost(bool, optional, tag="3", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// Whether the message is an automatically generated map entry type for the /// maps field. /// @@ -488,10 +488,10 @@ pub struct MessageOptions { /// instead. The option should only be implicitly set by the proto compiler /// parser. #[prost(bool, optional, tag="7")] - pub map_entry: ::std::option::Option, + pub map_entry: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct FieldOptions { @@ -500,14 +500,14 @@ pub struct FieldOptions { /// options below. This option is not yet implemented in the open source /// release -- sorry, we'll try to include it in a future version! #[prost(enumeration="field_options::CType", optional, tag="1", default="String")] - pub ctype: ::std::option::Option, + pub ctype: core::option::Option, /// The packed option can be enabled for repeated primitive fields to enable /// a more efficient representation on the wire. Rather than repeatedly /// writing the tag and type for each element, the entire array is encoded as /// a single length-delimited blob. In proto3, only explicit setting it to /// false will avoid using packed encoding. #[prost(bool, optional, tag="2")] - pub packed: ::std::option::Option, + pub packed: core::option::Option, /// The jstype option determines the JavaScript type used for values of the /// field. The option is permitted only for 64 bit integral and fixed types /// (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING @@ -520,7 +520,7 @@ pub struct FieldOptions { /// This option is an enum to permit additional types to be added, e.g. /// goog.math.Integer. #[prost(enumeration="field_options::JsType", optional, tag="6", default="JsNormal")] - pub jstype: ::std::option::Option, + pub jstype: core::option::Option, /// Should this field be parsed lazily? Lazy applies only to message-type /// fields. It means that when the outer message is initially parsed, the /// inner message's contents will not be parsed but instead stored in encoded @@ -550,19 +550,19 @@ pub struct FieldOptions { /// check its required fields, regardless of whether or not the message has /// been parsed. #[prost(bool, optional, tag="5", default="false")] - pub lazy: ::std::option::Option, + pub lazy: core::option::Option, /// Is this field deprecated? /// Depending on the target platform, this can emit Deprecated annotations /// for accessors, or it will be completely ignored; in the very least, this /// is a formalization for deprecating fields. #[prost(bool, optional, tag="3", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// For Google-internal migration only. Do not use. #[prost(bool, optional, tag="10", default="false")] - pub weak: ::std::option::Option, + pub weak: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } pub mod field_options { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] @@ -588,23 +588,23 @@ pub mod field_options { pub struct OneofOptions { /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumOptions { /// Set this option to true to allow mapping different tag names to the same /// value. #[prost(bool, optional, tag="2")] - pub allow_alias: ::std::option::Option, + pub allow_alias: core::option::Option, /// Is this enum deprecated? /// Depending on the target platform, this can emit Deprecated annotations /// for the enum, or it will be completely ignored; in the very least, this /// is a formalization for deprecating enums. #[prost(bool, optional, tag="3", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct EnumValueOptions { @@ -613,10 +613,10 @@ pub struct EnumValueOptions { /// for the enum value, or it will be completely ignored; in the very least, /// this is a formalization for deprecating enum values. #[prost(bool, optional, tag="1", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct ServiceOptions { @@ -630,10 +630,10 @@ pub struct ServiceOptions { /// for the service, or it will be completely ignored; in the very least, /// this is a formalization for deprecating services. #[prost(bool, optional, tag="33", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct MethodOptions { @@ -647,12 +647,12 @@ pub struct MethodOptions { /// for the method, or it will be completely ignored; in the very least, /// this is a formalization for deprecating methods. #[prost(bool, optional, tag="33", default="false")] - pub deprecated: ::std::option::Option, + pub deprecated: core::option::Option, #[prost(enumeration="method_options::IdempotencyLevel", optional, tag="34", default="IdempotencyUnknown")] - pub idempotency_level: ::std::option::Option, + pub idempotency_level: core::option::Option, /// The parser stores options it doesn't recognize here. See above. #[prost(message, repeated, tag="999")] - pub uninterpreted_option: ::std::vec::Vec, + pub uninterpreted_option: prost::alloc::vec::Vec, } pub mod method_options { /// Is this method side-effect-free (or safe in HTTP parlance), or idempotent, @@ -677,21 +677,21 @@ pub mod method_options { #[derive(Clone, PartialEq, ::prost::Message)] pub struct UninterpretedOption { #[prost(message, repeated, tag="2")] - pub name: ::std::vec::Vec, + pub name: prost::alloc::vec::Vec, /// The value of the uninterpreted option, in whatever type the tokenizer /// identified it as during parsing. Exactly one of these should be set. #[prost(string, optional, tag="3")] - pub identifier_value: ::std::option::Option, + pub identifier_value: core::option::Option, #[prost(uint64, optional, tag="4")] - pub positive_int_value: ::std::option::Option, + pub positive_int_value: core::option::Option, #[prost(int64, optional, tag="5")] - pub negative_int_value: ::std::option::Option, + pub negative_int_value: core::option::Option, #[prost(double, optional, tag="6")] - pub double_value: ::std::option::Option, + pub double_value: core::option::Option, #[prost(bytes, optional, tag="7")] - pub string_value: ::std::option::Option>, + pub string_value: core::option::Option>, #[prost(string, optional, tag="8")] - pub aggregate_value: ::std::option::Option, + pub aggregate_value: core::option::Option, } pub mod uninterpreted_option { /// The name of the uninterpreted option. Each string represents a segment in @@ -702,7 +702,7 @@ pub mod uninterpreted_option { #[derive(Clone, PartialEq, ::prost::Message)] pub struct NamePart { #[prost(string, required, tag="1")] - pub name_part: std::string::String, + pub name_part: prost::alloc::string::String, #[prost(bool, required, tag="2")] pub is_extension: bool, } @@ -758,7 +758,7 @@ pub struct SourceCodeInfo { /// ignore those that it doesn't understand, as more types of locations could /// be recorded in the future. #[prost(message, repeated, tag="1")] - pub location: ::std::vec::Vec, + pub location: prost::alloc::vec::Vec, } pub mod source_code_info { #[derive(Clone, PartialEq, ::prost::Message)] @@ -787,14 +787,14 @@ pub mod source_code_info { /// this path refers to the whole field declaration (from the beginning /// of the label to the terminating semicolon). #[prost(int32, repeated, tag="1")] - pub path: ::std::vec::Vec, + pub path: prost::alloc::vec::Vec, /// Always has exactly three or four elements: start line, start column, /// end line (optional, otherwise assumed same as start line), end column. /// These are packed into a single field for efficiency. Note that line /// and column numbers are zero-based -- typically you will want to add /// 1 to each before displaying to a user. #[prost(int32, repeated, tag="2")] - pub span: ::std::vec::Vec, + pub span: prost::alloc::vec::Vec, /// If this SourceCodeInfo represents a complete declaration, these are any /// comments appearing before and after the declaration which appear to be /// attached to the declaration. @@ -843,11 +843,11 @@ pub mod source_code_info { /// /// // ignored detached comments. #[prost(string, optional, tag="3")] - pub leading_comments: ::std::option::Option, + pub leading_comments: core::option::Option, #[prost(string, optional, tag="4")] - pub trailing_comments: ::std::option::Option, + pub trailing_comments: core::option::Option, #[prost(string, repeated, tag="6")] - pub leading_detached_comments: ::std::vec::Vec, + pub leading_detached_comments: prost::alloc::vec::Vec, } } /// Describes the relationship between generated code and its original source @@ -858,7 +858,7 @@ pub struct GeneratedCodeInfo { /// An Annotation connects some span of text in generated code to an element /// of its generating .proto file. #[prost(message, repeated, tag="1")] - pub annotation: ::std::vec::Vec, + pub annotation: prost::alloc::vec::Vec, } pub mod generated_code_info { #[derive(Clone, PartialEq, ::prost::Message)] @@ -866,19 +866,19 @@ pub mod generated_code_info { /// Identifies the element in the original source .proto file. This field /// is formatted the same as SourceCodeInfo.Location.path. #[prost(int32, repeated, tag="1")] - pub path: ::std::vec::Vec, + pub path: prost::alloc::vec::Vec, /// Identifies the filesystem path to the original source .proto. #[prost(string, optional, tag="2")] - pub source_file: ::std::option::Option, + pub source_file: core::option::Option, /// Identifies the starting offset in bytes in the generated code /// that relates to the identified object. #[prost(int32, optional, tag="3")] - pub begin: ::std::option::Option, + pub begin: core::option::Option, /// Identifies the ending offset in bytes in the generated code that /// relates to the identified offset. The end offset should be one past /// the last relevant byte (so the length of the text = end - begin). #[prost(int32, optional, tag="4")] - pub end: ::std::option::Option, + pub end: core::option::Option, } } /// `Any` contains an arbitrary serialized protocol buffer message along with a @@ -992,10 +992,10 @@ pub struct Any { /// used with implementation specific semantics. /// #[prost(string, tag="1")] - pub type_url: std::string::String, + pub type_url: prost::alloc::string::String, /// Must be a valid serialized protocol buffer of the above specified type. #[prost(bytes, tag="2")] - pub value: std::vec::Vec, + pub value: prost::alloc::vec::Vec, } /// `SourceContext` represents information about the source of a /// protobuf element, like the file in which it is defined. @@ -1004,26 +1004,26 @@ pub struct SourceContext { /// The path-qualified name of the .proto file that contained the associated /// protobuf element. For example: `"google/protobuf/source_context.proto"`. #[prost(string, tag="1")] - pub file_name: std::string::String, + pub file_name: prost::alloc::string::String, } /// A protocol buffer message type. #[derive(Clone, PartialEq, ::prost::Message)] pub struct Type { /// The fully qualified message name. #[prost(string, tag="1")] - pub name: std::string::String, + pub name: prost::alloc::string::String, /// The list of fields. #[prost(message, repeated, tag="2")] - pub fields: ::std::vec::Vec, + pub fields: prost::alloc::vec::Vec, /// The list of types appearing in `oneof` definitions in this type. #[prost(string, repeated, tag="3")] - pub oneofs: ::std::vec::Vec, + pub oneofs: prost::alloc::vec::Vec, /// The protocol buffer options. #[prost(message, repeated, tag="4")] - pub options: ::std::vec::Vec