You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/04/19 19:00:52 UTC
[avro] 01/01: AVRO-3496: Rust: Use visitor.visit_borrowed_str() when possible
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch avro-3496-visit_borrowed_str
in repository https://gitbox.apache.org/repos/asf/avro.git
commit 13adf21dd330a504bd64e51976c57459744acf00
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Tue Apr 19 22:00:13 2022 +0300
AVRO-3496: Rust: Use visitor.visit_borrowed_str() when possible
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
lang/rust/avro/src/de.rs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lang/rust/avro/src/de.rs b/lang/rust/avro/src/de.rs
index 6324caea9..24e9958b2 100644
--- a/lang/rust/avro/src/de.rs
+++ b/lang/rust/avro/src/de.rs
@@ -262,7 +262,7 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
Value::Double(d) => visitor.visit_f64(d),
Value::Record(ref fields) => visitor.visit_map(StructDeserializer::new(fields)),
Value::Array(ref fields) => visitor.visit_seq(SeqDeserializer::new(fields)),
- Value::String(ref s) => visitor.visit_str(s),
+ Value::String(ref s) => visitor.visit_borrowed_str(s),
Value::Map(ref items) => visitor.visit_map(MapDeserializer::new(items)),
_ => Err(de::Error::custom(format!(
"unsupported union: {:?}",
@@ -271,7 +271,7 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
},
Value::Record(ref fields) => visitor.visit_map(StructDeserializer::new(fields)),
Value::Array(ref fields) => visitor.visit_seq(SeqDeserializer::new(fields)),
- Value::String(ref s) => visitor.visit_str(s),
+ Value::String(ref s) => visitor.visit_borrowed_str(s),
Value::Map(ref items) => visitor.visit_map(MapDeserializer::new(items)),
value => Err(de::Error::custom(format!(
"incorrect value of type: {:?}",
@@ -296,10 +296,10 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
V: Visitor<'de>,
{
match *self.input {
- Value::String(ref s) => visitor.visit_str(s),
+ Value::String(ref s) => visitor.visit_borrowed_str(s),
Value::Bytes(ref bytes) | Value::Fixed(_, ref bytes) => ::std::str::from_utf8(bytes)
.map_err(|e| de::Error::custom(e.to_string()))
- .and_then(|s| visitor.visit_str(s)),
+ .and_then(|s| visitor.visit_borrowed_str(s)),
Value::Uuid(ref u) => visitor.visit_str(&u.to_string()),
_ => Err(de::Error::custom("not a string|bytes|fixed")),
}
@@ -310,14 +310,14 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
V: Visitor<'de>,
{
match *self.input {
- Value::String(ref s) => visitor.visit_string(s.to_owned()),
+ Value::String(ref s) => visitor.visit_borrowed_str(s),
Value::Bytes(ref bytes) | Value::Fixed(_, ref bytes) => {
String::from_utf8(bytes.to_owned())
.map_err(|e| de::Error::custom(e.to_string()))
.and_then(|s| visitor.visit_string(s))
}
Value::Union(_i, ref x) => match **x {
- Value::String(ref s) => visitor.visit_string(s.to_owned()),
+ Value::String(ref s) => visitor.visit_borrowed_str(s),
_ => Err(de::Error::custom("not a string|bytes|fixed")),
},
_ => Err(de::Error::custom("not a string|bytes|fixed")),