Rename visit_enum_simple to visit_newtype_variant

This commit is contained in:
Erick Tryzelaar
2015-07-29 14:45:29 -07:00
parent 6cbb72decf
commit fefc010deb
6 changed files with 31 additions and 31 deletions
+2 -2
View File
@@ -632,10 +632,10 @@ impl<T, E> Serialize for Result<T, E> where T: Serialize, E: Serialize {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
match *self {
Result::Ok(ref value) => {
serializer.visit_enum_simple("Result", 0, "Ok", value)
serializer.visit_newtype_variant("Result", 0, "Ok", value)
}
Result::Err(ref value) => {
serializer.visit_enum_simple("Result", 1, "Err", value)
serializer.visit_newtype_variant("Result", 1, "Err", value)
}
}
}
+8 -5
View File
@@ -125,12 +125,15 @@ pub trait Serializer {
self.visit_unit()
}
/// The `visit_newtype_variant` allows a variant with a single item to be more efficiently
/// serialized than a variant with multiple items. By default it just serializes the value as a
/// tuple variant sequence.
#[inline]
fn visit_enum_simple<T>(&mut self,
name: &'static str,
variant_index: usize,
variant: &'static str,
value: T) -> Result<(), Self::Error>
fn visit_newtype_variant<T>(&mut self,
name: &'static str,
variant_index: usize,
variant: &'static str,
value: T) -> Result<(), Self::Error>
where T: Serialize,
{
self.visit_tuple_variant(