11//! Contains serializer for content of an XML element
22
33use crate :: de:: TEXT_KEY ;
4- use crate :: errors:: serialize:: DeError ;
54use crate :: se:: element:: { ElementSerializer , Struct , Tuple } ;
65use crate :: se:: simple_type:: { QuoteTarget , SimpleTypeSerializer } ;
7- use crate :: se:: { Indent , QuoteLevel , XmlName } ;
6+ use crate :: se:: { Indent , QuoteLevel , SeError , XmlName } ;
87use serde:: ser:: {
98 Impossible , Serialize , SerializeSeq , SerializeTuple , SerializeTupleStruct , Serializer ,
109} ;
@@ -36,7 +35,7 @@ macro_rules! write_primitive {
3635/// - units (`()`) and unit structs does not write anything;
3736/// - sequences, tuples and tuple structs are serialized without delimiters.
3837/// `[1, 2, 3]` would be serialized as `123` (if not using indent);
39- /// - structs and maps are not supported ([`DeError ::Unsupported`] is returned);
38+ /// - structs and maps are not supported ([`SeError ::Unsupported`] is returned);
4039/// - enums:
4140/// - unit variants are serialized as self-closed `<variant/>`;
4241/// - newtype variants are serialized as inner value wrapped in `<variant>...</variant>`;
@@ -108,7 +107,7 @@ impl<'w, 'i, W: Write> ContentSerializer<'w, 'i, W> {
108107
109108 /// Writes `name` as self-closed tag
110109 #[ inline]
111- pub ( super ) fn write_empty ( mut self , name : XmlName ) -> Result < ( ) , DeError > {
110+ pub ( super ) fn write_empty ( mut self , name : XmlName ) -> Result < ( ) , SeError > {
112111 self . write_indent ( ) ?;
113112 if self . expand_empty_elements {
114113 self . writer . write_char ( '<' ) ?;
@@ -125,9 +124,9 @@ impl<'w, 'i, W: Write> ContentSerializer<'w, 'i, W> {
125124 }
126125
127126 /// Writes simple type content between `name` tags
128- pub ( super ) fn write_wrapped < S > ( mut self , name : XmlName , serialize : S ) -> Result < ( ) , DeError >
127+ pub ( super ) fn write_wrapped < S > ( mut self , name : XmlName , serialize : S ) -> Result < ( ) , SeError >
129128 where
130- S : for < ' a > FnOnce ( SimpleTypeSerializer < ' i , & ' a mut W > ) -> Result < & ' a mut W , DeError > ,
129+ S : for < ' a > FnOnce ( SimpleTypeSerializer < ' i , & ' a mut W > ) -> Result < & ' a mut W , SeError > ,
131130 {
132131 self . write_indent ( ) ?;
133132 self . writer . write_char ( '<' ) ?;
@@ -142,7 +141,7 @@ impl<'w, 'i, W: Write> ContentSerializer<'w, 'i, W> {
142141 Ok ( ( ) )
143142 }
144143
145- pub ( super ) fn write_indent ( & mut self ) -> Result < ( ) , DeError > {
144+ pub ( super ) fn write_indent ( & mut self ) -> Result < ( ) , SeError > {
146145 if self . write_indent {
147146 self . indent . write_indent ( & mut self . writer ) ?;
148147 self . write_indent = false ;
@@ -153,7 +152,7 @@ impl<'w, 'i, W: Write> ContentSerializer<'w, 'i, W> {
153152
154153impl < ' w , ' i , W : Write > Serializer for ContentSerializer < ' w , ' i , W > {
155154 type Ok = ( ) ;
156- type Error = DeError ;
155+ type Error = SeError ;
157156
158157 type SerializeSeq = Self ;
159158 type SerializeTuple = Self ;
@@ -310,7 +309,7 @@ impl<'w, 'i, W: Write> Serializer for ContentSerializer<'w, 'i, W> {
310309 }
311310
312311 fn serialize_map ( self , _len : Option < usize > ) -> Result < Self :: SerializeMap , Self :: Error > {
313- Err ( DeError :: Unsupported (
312+ Err ( SeError :: Unsupported (
314313 "serialization of map types is not supported in `$value` field" . into ( ) ,
315314 ) )
316315 }
@@ -321,7 +320,7 @@ impl<'w, 'i, W: Write> Serializer for ContentSerializer<'w, 'i, W> {
321320 name : & ' static str ,
322321 _len : usize ,
323322 ) -> Result < Self :: SerializeStruct , Self :: Error > {
324- Err ( DeError :: Unsupported (
323+ Err ( SeError :: Unsupported (
325324 format ! ( "serialization of struct `{name}` is not supported in `$value` field" ) . into ( ) ,
326325 ) )
327326 }
@@ -345,7 +344,7 @@ impl<'w, 'i, W: Write> Serializer for ContentSerializer<'w, 'i, W> {
345344 len : usize ,
346345 ) -> Result < Self :: SerializeStructVariant , Self :: Error > {
347346 if variant == TEXT_KEY {
348- Err ( DeError :: Unsupported (
347+ Err ( SeError :: Unsupported (
349348 format ! ( "cannot serialize `$text` struct variant of `{}` enum" , name) . into ( ) ,
350349 ) )
351350 } else {
@@ -360,7 +359,7 @@ impl<'w, 'i, W: Write> Serializer for ContentSerializer<'w, 'i, W> {
360359
361360impl < ' w , ' i , W : Write > SerializeSeq for ContentSerializer < ' w , ' i , W > {
362361 type Ok = ( ) ;
363- type Error = DeError ;
362+ type Error = SeError ;
364363
365364 fn serialize_element < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
366365 where
@@ -380,7 +379,7 @@ impl<'w, 'i, W: Write> SerializeSeq for ContentSerializer<'w, 'i, W> {
380379
381380impl < ' w , ' i , W : Write > SerializeTuple for ContentSerializer < ' w , ' i , W > {
382381 type Ok = ( ) ;
383- type Error = DeError ;
382+ type Error = SeError ;
384383
385384 #[ inline]
386385 fn serialize_element < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
@@ -398,7 +397,7 @@ impl<'w, 'i, W: Write> SerializeTuple for ContentSerializer<'w, 'i, W> {
398397
399398impl < ' w , ' i , W : Write > SerializeTupleStruct for ContentSerializer < ' w , ' i , W > {
400399 type Ok = ( ) ;
401- type Error = DeError ;
400+ type Error = SeError ;
402401
403402 #[ inline]
404403 fn serialize_field < T > ( & mut self , value : & T ) -> Result < ( ) , Self :: Error >
@@ -573,7 +572,7 @@ pub(super) mod tests {
573572 } ;
574573
575574 match $data. serialize( ser) . unwrap_err( ) {
576- DeError :: $kind( e) => assert_eq!( e, $reason) ,
575+ SeError :: $kind( e) => assert_eq!( e, $reason) ,
577576 e => panic!(
578577 "Expected `Err({}({}))`, but got `{:?}`" ,
579578 stringify!( $kind) ,
@@ -1013,7 +1012,7 @@ pub(super) mod tests {
10131012 } ;
10141013
10151014 match $data. serialize( ser) . unwrap_err( ) {
1016- DeError :: $kind( e) => assert_eq!( e, $reason) ,
1015+ SeError :: $kind( e) => assert_eq!( e, $reason) ,
10171016 e => panic!(
10181017 "Expected `Err({}({}))`, but got `{:?}`" ,
10191018 stringify!( $kind) ,
0 commit comments