diff options
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | out/version.rs | 6 | ||||
-rw-r--r-- | src/buf_read_iter.rs | 4 | ||||
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/message.rs | 16 | ||||
-rw-r--r-- | src/reflect/map.rs | 16 | ||||
-rw-r--r-- | src/reflect/optional.rs | 22 | ||||
-rw-r--r-- | src/reflect/repeated.rs | 28 | ||||
-rw-r--r-- | src/reflect/value.rs | 2 | ||||
-rw-r--r-- | src/stream.rs | 16 | ||||
-rw-r--r-- | src/text_format.rs | 10 |
16 files changed, 68 insertions, 71 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index e7b2111..2bb6739 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "dddcb17948d6ad78fe610af5a7f016d871d2a380" + "sha1": "09619bc3a85243f092e68ab9ba1f2c5573d5a85b" } } @@ -9,7 +9,6 @@ genrule { rust_library { name: "libprotobuf", - // has rustc warnings host_supported: true, crate_name: "protobuf", srcs: [ @@ -13,7 +13,7 @@ [package] edition = "2018" name = "protobuf" -version = "2.18.0" +version = "2.18.1" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] description = "Rust implementation of Google protocol buffers\n" homepage = "https://github.com/stepancheg/rust-protobuf/" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index b751373..3b03c96 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,7 @@ [package] name = "protobuf" -version = "2.18.0" +version = "2.18.1" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] edition = "2018" license = "MIT" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/protobuf/protobuf-2.18.0.crate" + value: "https://static.crates.io/crates/protobuf/protobuf-2.18.1.crate" } - version: "2.18.0" + version: "2.18.1" license_type: NOTICE last_upgrade_date { year: 2020 - month: 10 - day: 6 + month: 11 + day: 24 } } diff --git a/out/version.rs b/out/version.rs index 50d3ae8..22c110e 100644 --- a/out/version.rs +++ b/out/version.rs @@ -1,7 +1,7 @@ /// protobuf crate version -pub const VERSION: &'static str = "2.18.0"; +pub const VERSION: &'static str = "2.18.1"; /// This symbol is used by codegen #[doc(hidden)] -pub const VERSION_IDENT: &'static str = "VERSION_2_18_0"; +pub const VERSION_IDENT: &'static str = "VERSION_2_18_1"; /// This symbol can be referenced to assert that proper version of crate is used -pub const VERSION_2_18_0: () = (); +pub const VERSION_2_18_1: () = (); diff --git a/src/buf_read_iter.rs b/src/buf_read_iter.rs index 149a2ea..8b4dbf5 100644 --- a/src/buf_read_iter.rs +++ b/src/buf_read_iter.rs @@ -29,8 +29,8 @@ const NO_LIMIT: u64 = u64::MAX; /// Hold all possible combinations of input source enum InputSource<'a> { - BufRead(&'a mut BufRead), - Read(BufReader<&'a mut Read>), + BufRead(&'a mut dyn BufRead), + Read(BufReader<&'a mut dyn Read>), Slice(&'a [u8]), #[cfg(feature = "bytes")] Bytes(&'a Bytes), diff --git a/src/error.rs b/src/error.rs index 9e5a7e1..3f06909 100644 --- a/src/error.rs +++ b/src/error.rs @@ -112,7 +112,7 @@ impl Error for ProtobufError { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { &ProtobufError::IoError(ref e) => Some(e), &ProtobufError::Utf8(ref e) => Some(e), @@ -2,8 +2,6 @@ #![deny(missing_docs)] #![deny(broken_intra_doc_links)] -// Because we need compat with Rust 1.26 -#![allow(bare_trait_objects)] #[cfg(feature = "bytes")] extern crate bytes; diff --git a/src/message.rs b/src/message.rs index 1b1f39f..2f1a1e7 100644 --- a/src/message.rs +++ b/src/message.rs @@ -97,7 +97,7 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { } /// Write the message to the writer. - fn write_to_writer(&self, w: &mut Write) -> ProtobufResult<()> { + fn write_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()> { w.with_coded_output_stream(|os| self.write_to(os)) } @@ -126,7 +126,7 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { /// Write the message to the writer, prepend the message with message length /// encoded as varint. - fn write_length_delimited_to_writer(&self, w: &mut Write) -> ProtobufResult<()> { + fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()> { w.with_coded_output_stream(|os| self.write_length_delimited_to(os)) } @@ -147,15 +147,15 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { } /// View self as `Any`. - fn as_any(&self) -> &Any; + fn as_any(&self) -> &dyn Any; /// View self as mutable `Any`. - fn as_any_mut(&mut self) -> &mut Any { + fn as_any_mut(&mut self) -> &mut dyn Any { panic!() } /// Convert boxed self to boxed `Any`. - fn into_any(self: Box<Self>) -> Box<Any> { + fn into_any(self: Box<Self>) -> Box<dyn Any> { panic!() } @@ -209,7 +209,7 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync { Self: Sized; } -pub fn message_down_cast<'a, M: Message + 'a>(m: &'a Message) -> &'a M { +pub fn message_down_cast<'a, M: Message + 'a>(m: &'a dyn Message) -> &'a M { m.as_any().downcast_ref::<M>().unwrap() } @@ -223,7 +223,7 @@ pub fn parse_from<M: Message>(is: &mut CodedInputStream) -> ProtobufResult<M> { /// Parse message from reader. /// Parse stops on EOF or when error encountered. -pub fn parse_from_reader<M: Message>(reader: &mut Read) -> ProtobufResult<M> { +pub fn parse_from_reader<M: Message>(reader: &mut dyn Read) -> ProtobufResult<M> { reader.with_coded_input_stream(|is| parse_from::<M>(is)) } @@ -254,7 +254,7 @@ pub fn parse_length_delimited_from<M: Message>(is: &mut CodedInputStream) -> Pro /// /// This function is deprecated and will be removed in the next major release. #[deprecated] -pub fn parse_length_delimited_from_reader<M: Message>(r: &mut Read) -> ProtobufResult<M> { +pub fn parse_length_delimited_from_reader<M: Message>(r: &mut dyn Read) -> ProtobufResult<M> { // TODO: wrong: we may read length first, and then read exact number of bytes needed r.with_coded_input_stream(|is| is.read_message::<M>()) } diff --git a/src/reflect/map.rs b/src/reflect/map.rs index 9f03123..c6aff60 100644 --- a/src/reflect/map.rs +++ b/src/reflect/map.rs @@ -26,7 +26,7 @@ impl<K: ProtobufValue + Eq + Hash + 'static, V: ProtobufValue + 'static> Reflect } trait ReflectMapIterTrait<'a> { - fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)>; + fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)>; } struct ReflectMapIterImpl<'a, K: Eq + Hash + 'static, V: 'static> { @@ -36,29 +36,29 @@ struct ReflectMapIterImpl<'a, K: Eq + Hash + 'static, V: 'static> { impl<'a, K: ProtobufValue + Eq + Hash + 'static, V: ProtobufValue + 'static> ReflectMapIterTrait<'a> for ReflectMapIterImpl<'a, K, V> { - fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)> { + fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)> { match self.iter.next() { - Some((k, v)) => Some((k as &ProtobufValue, v as &ProtobufValue)), + Some((k, v)) => Some((k as &dyn ProtobufValue, v as &dyn ProtobufValue)), None => None, } } } pub struct ReflectMapIter<'a> { - imp: Box<ReflectMapIterTrait<'a> + 'a>, + imp: Box<dyn ReflectMapIterTrait<'a> + 'a>, } impl<'a> Iterator for ReflectMapIter<'a> { - type Item = (&'a ProtobufValue, &'a ProtobufValue); + type Item = (&'a dyn ProtobufValue, &'a dyn ProtobufValue); - fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)> { + fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)> { self.imp.next() } } -impl<'a> IntoIterator for &'a ReflectMap { +impl<'a> IntoIterator for &'a dyn ReflectMap { type IntoIter = ReflectMapIter<'a>; - type Item = (&'a ProtobufValue, &'a ProtobufValue); + type Item = (&'a dyn ProtobufValue, &'a dyn ProtobufValue); fn into_iter(self) -> Self::IntoIter { self.reflect_iter() diff --git a/src/reflect/optional.rs b/src/reflect/optional.rs index ba6cbaf..f81f973 100644 --- a/src/reflect/optional.rs +++ b/src/reflect/optional.rs @@ -5,17 +5,17 @@ use super::value::ProtobufValue; use crate::singular::*; pub trait ReflectOptional: 'static { - fn to_option(&self) -> Option<&ProtobufValue>; + fn to_option(&self) -> Option<&dyn ProtobufValue>; - fn set_value(&mut self, value: &ProtobufValue); + fn set_value(&mut self, value: &dyn ProtobufValue); } impl<V: ProtobufValue + Clone + 'static> ReflectOptional for Option<V> { - fn to_option(&self) -> Option<&ProtobufValue> { - self.as_ref().map(|v| v as &ProtobufValue) + fn to_option(&self) -> Option<&dyn ProtobufValue> { + self.as_ref().map(|v| v as &dyn ProtobufValue) } - fn set_value(&mut self, value: &ProtobufValue) { + fn set_value(&mut self, value: &dyn ProtobufValue) { match value.as_any().downcast_ref::<V>() { Some(v) => mem::replace(self, Some(v.clone())), None => panic!(), @@ -24,11 +24,11 @@ impl<V: ProtobufValue + Clone + 'static> ReflectOptional for Option<V> { } impl<V: ProtobufValue + Clone + 'static> ReflectOptional for SingularField<V> { - fn to_option(&self) -> Option<&ProtobufValue> { - self.as_ref().map(|v| v as &ProtobufValue) + fn to_option(&self) -> Option<&dyn ProtobufValue> { + self.as_ref().map(|v| v as &dyn ProtobufValue) } - fn set_value(&mut self, value: &ProtobufValue) { + fn set_value(&mut self, value: &dyn ProtobufValue) { match value.as_any().downcast_ref::<V>() { Some(v) => mem::replace(self, SingularField::some(v.clone())), None => panic!(), @@ -37,11 +37,11 @@ impl<V: ProtobufValue + Clone + 'static> ReflectOptional for SingularField<V> { } impl<V: ProtobufValue + Clone + 'static> ReflectOptional for SingularPtrField<V> { - fn to_option(&self) -> Option<&ProtobufValue> { - self.as_ref().map(|v| v as &ProtobufValue) + fn to_option(&self) -> Option<&dyn ProtobufValue> { + self.as_ref().map(|v| v as &dyn ProtobufValue) } - fn set_value(&mut self, value: &ProtobufValue) { + fn set_value(&mut self, value: &dyn ProtobufValue) { match value.as_any().downcast_ref::<V>() { Some(v) => mem::replace(self, SingularPtrField::some(v.clone())), None => panic!(), diff --git a/src/reflect/repeated.rs b/src/reflect/repeated.rs index 43e265d..be232f4 100644 --- a/src/reflect/repeated.rs +++ b/src/reflect/repeated.rs @@ -8,7 +8,7 @@ use crate::repeated::RepeatedField; pub trait ReflectRepeated: 'static { fn reflect_iter(&self) -> ReflectRepeatedIter; fn len(&self) -> usize; - fn get(&self, index: usize) -> &ProtobufValue; + fn get(&self, index: usize) -> &dyn ProtobufValue; } impl<V: ProtobufValue + 'static> ReflectRepeated for Vec<V> { @@ -22,7 +22,7 @@ impl<V: ProtobufValue + 'static> ReflectRepeated for Vec<V> { Vec::len(self) } - fn get(&self, index: usize) -> &ProtobufValue { + fn get(&self, index: usize) -> &dyn ProtobufValue { &self[index] } } @@ -39,7 +39,7 @@ impl<V: ProtobufValue + 'static> ReflectRepeated for [V] { <[_]>::len(self) } - fn get(&self, index: usize) -> &ProtobufValue { + fn get(&self, index: usize) -> &dyn ProtobufValue { &self[index] } } @@ -55,13 +55,13 @@ impl<V: ProtobufValue + 'static> ReflectRepeated for RepeatedField<V> { RepeatedField::len(self) } - fn get(&self, index: usize) -> &ProtobufValue { + fn get(&self, index: usize) -> &dyn ProtobufValue { &self[index] } } trait ReflectRepeatedIterTrait<'a> { - fn next(&mut self) -> Option<&'a ProtobufValue>; + fn next(&mut self) -> Option<&'a dyn ProtobufValue>; } struct ReflectRepeatedIterImplSlice<'a, V: ProtobufValue + 'static> { @@ -71,26 +71,26 @@ struct ReflectRepeatedIterImplSlice<'a, V: ProtobufValue + 'static> { impl<'a, V: ProtobufValue + 'static> ReflectRepeatedIterTrait<'a> for ReflectRepeatedIterImplSlice<'a, V> { - fn next(&mut self) -> Option<&'a ProtobufValue> { - self.iter.next().map(|v| v as &ProtobufValue) + fn next(&mut self) -> Option<&'a dyn ProtobufValue> { + self.iter.next().map(|v| v as &dyn ProtobufValue) } } pub struct ReflectRepeatedIter<'a> { - imp: Box<ReflectRepeatedIterTrait<'a> + 'a>, + imp: Box<dyn ReflectRepeatedIterTrait<'a> + 'a>, } impl<'a> Iterator for ReflectRepeatedIter<'a> { - type Item = &'a ProtobufValue; + type Item = &'a dyn ProtobufValue; fn next(&mut self) -> Option<Self::Item> { self.imp.next() } } -impl<'a> IntoIterator for &'a ReflectRepeated { +impl<'a> IntoIterator for &'a dyn ReflectRepeated { type IntoIter = ReflectRepeatedIter<'a>; - type Item = &'a ProtobufValue; + type Item = &'a dyn ProtobufValue; fn into_iter(self) -> Self::IntoIter { self.reflect_iter() @@ -110,7 +110,7 @@ pub trait ReflectRepeatedMessage<'a> { } pub enum ReflectRepeatedRef<'a> { - Generic(&'a ReflectRepeated), + Generic(&'a dyn ReflectRepeated), U32(&'a [u32]), U64(&'a [u64]), I32(&'a [i32]), @@ -120,8 +120,8 @@ pub enum ReflectRepeatedRef<'a> { Bool(&'a [bool]), String(&'a [String]), Bytes(&'a [Vec<u8>]), - Enum(Box<ReflectRepeatedEnum<'a> + 'a>), - Message(Box<ReflectRepeatedMessage<'a> + 'a>), + Enum(Box<dyn ReflectRepeatedEnum<'a> + 'a>), + Message(Box<dyn ReflectRepeatedMessage<'a> + 'a>), } impl<'a> ReflectRepeatedRef<'a> { diff --git a/src/reflect/value.rs b/src/reflect/value.rs index 2671805..16d5266 100644 --- a/src/reflect/value.rs +++ b/src/reflect/value.rs @@ -14,7 +14,7 @@ pub trait ProtobufValue: Any + 'static { fn as_ref(&self) -> ReflectValueRef; /// Convert to `Any` - fn as_any(&self) -> &Any { + fn as_any(&self) -> &dyn Any { unimplemented!() } diff --git a/src/stream.rs b/src/stream.rs index d503fd7..dc45953 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -48,7 +48,7 @@ pub mod wire_format { /// Tag occupies 3 bits pub const TAG_TYPE_BITS: u32 = 3; /// Tag mask - pub const TAG_TYPE_MASK: u32 = (1u32 << TAG_TYPE_BITS as usize) - 1; + pub const TAG_TYPE_MASK: u32 = (1u32 << TAG_TYPE_BITS) - 1; /// Max possible field number pub const FIELD_NUMBER_MAX: u32 = 0x1fffffff; @@ -158,14 +158,14 @@ impl<'a> CodedInputStream<'a> { /// Wrap a `Read`. /// /// Note resulting `CodedInputStream` is buffered even if `Read` is not. - pub fn new(read: &'a mut Read) -> CodedInputStream<'a> { + pub fn new(read: &'a mut dyn Read) -> CodedInputStream<'a> { CodedInputStream::from_buf_read_iter(BufReadIter::from_read(read)) } /// Create from `BufRead`. /// /// `CodedInputStream` will utilize `BufRead` buffer. - pub fn from_buffered_reader(buf_read: &'a mut BufRead) -> CodedInputStream<'a> { + pub fn from_buffered_reader(buf_read: &'a mut dyn BufRead) -> CodedInputStream<'a> { CodedInputStream::from_buf_read_iter(BufReadIter::from_buf_read(buf_read)) } @@ -854,7 +854,7 @@ pub trait WithCodedOutputStream { F: FnOnce(&mut CodedOutputStream) -> ProtobufResult<T>; } -impl<'a> WithCodedOutputStream for &'a mut (Write + 'a) { +impl<'a> WithCodedOutputStream for &'a mut (dyn Write + 'a) { fn with_coded_output_stream<T, F>(self, cb: F) -> ProtobufResult<T> where F: FnOnce(&mut CodedOutputStream) -> ProtobufResult<T>, @@ -896,7 +896,7 @@ pub trait WithCodedInputStream { F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>; } -impl<'a> WithCodedInputStream for &'a mut (Read + 'a) { +impl<'a> WithCodedInputStream for &'a mut (dyn Read + 'a) { fn with_coded_input_stream<T, F>(self, cb: F) -> ProtobufResult<T> where F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>, @@ -908,7 +908,7 @@ impl<'a> WithCodedInputStream for &'a mut (Read + 'a) { } } -impl<'a> WithCodedInputStream for &'a mut (BufRead + 'a) { +impl<'a> WithCodedInputStream for &'a mut (dyn BufRead + 'a) { fn with_coded_input_stream<T, F>(self, cb: F) -> ProtobufResult<T> where F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>, @@ -946,7 +946,7 @@ impl<'a> WithCodedInputStream for &'a Bytes { } enum OutputTarget<'a> { - Write(&'a mut Write, Vec<u8>), + Write(&'a mut dyn Write, Vec<u8>), Vec(&'a mut Vec<u8>), Bytes, } @@ -964,7 +964,7 @@ impl<'a> CodedOutputStream<'a> { /// Construct from given `Write`. /// /// `CodedOutputStream` is buffered even if `Write` is not - pub fn new(writer: &'a mut Write) -> CodedOutputStream<'a> { + pub fn new(writer: &'a mut dyn Write) -> CodedOutputStream<'a> { let buffer_len = OUTPUT_STREAM_BUFFER_SIZE; let mut buffer_storage = Vec::with_capacity(buffer_len); diff --git a/src/text_format.rs b/src/text_format.rs index 59bd07a..3cbe13d 100644 --- a/src/text_format.rs +++ b/src/text_format.rs @@ -219,7 +219,7 @@ fn print_field( print_end_field(buf, pretty); } -fn print_to_internal(m: &Message, buf: &mut String, pretty: bool, indent: usize) { +fn print_to_internal(m: &dyn Message, buf: &mut String, pretty: bool, indent: usize) { let d = m.descriptor(); let mut first = true; for f in d.fields() { @@ -266,23 +266,23 @@ fn print_to_internal(m: &Message, buf: &mut String, pretty: bool, indent: usize) } /// Text-format -pub fn print_to(m: &Message, buf: &mut String) { +pub fn print_to(m: &dyn Message, buf: &mut String) { print_to_internal(m, buf, false, 0) } -fn print_to_string_internal(m: &Message, pretty: bool) -> String { +fn print_to_string_internal(m: &dyn Message, pretty: bool) -> String { let mut r = String::new(); print_to_internal(m, &mut r, pretty, 0); r.to_string() } /// Text-format -pub fn print_to_string(m: &Message) -> String { +pub fn print_to_string(m: &dyn Message) -> String { print_to_string_internal(m, false) } /// Text-format to `fmt::Formatter`. -pub fn fmt(m: &Message, f: &mut fmt::Formatter) -> fmt::Result { +pub fn fmt(m: &dyn Message, f: &mut fmt::Formatter) -> fmt::Result { let pretty = f.alternate(); f.write_str(&print_to_string_internal(m, pretty)) } |