/// A serializer used to serialize content of an element. It does not write /// surrounding tags. Unlike the [`ElementSerializer`], this serializer serializes /// enums using variant names as tag names, i. e. as `<variant>...</variant>`. /// /// Returns the classification of the last written type. /// /// This serializer does the following: /// - numbers converted to a decimal representation and serialized as naked strings; /// - booleans serialized ether as `"true"` or `"false"`; /// - strings and characters are serialized as naked strings; /// - `None` does not write anything; /// - `Some` and newtypes are serialized as an inner type using the same serializer; /// - units (`()`) and unit structs does not write anything; /// - sequences, tuples and tuple structs are serialized without delimiters. /// `[1, 2, 3]` would be serialized as `123` (if not using indent); /// - structs and maps are not supported ([`SeError::Unsupported`] is returned); /// - enums: /// - unit variants are serialized as self-closed `<variant/>`; /// - newtype variants are serialized as inner value wrapped in `<variant>...</variant>`; /// - tuple variants are serialized as sequences where each element is wrapped /// in `<variant>...</variant>`; /// - struct variants are serialized as a sequence of fields wrapped in /// `<variant>...</variant>`. Each field is serialized recursively using /// either [`ElementSerializer`], `ContentSerializer` (`$value` fields), or /// [`SimpleTypeSerializer`] (`$text` fields). In particular, the empty struct /// is serialized as `<variant/>`; /// /// Usage of empty tags depends on the [`Self::expand_empty_elements`] setting. /// /// The difference between this serializer and [`SimpleTypeSerializer`] is in how /// sequences and maps are serialized. Unlike `SimpleTypeSerializer` it supports /// any types in sequences and serializes them as list of elements, but that has /// drawbacks. Sequence of primitives would be serialized without delimiters and /// it will be impossible to distinguish between them. Even worse, when serializing /// with indent, sequence of strings become one big string with additional content /// and it would be impossible to distinguish between content of the original /// strings and inserted indent characters. pubstruct ContentSerializer<'w, 'i, W: Write> { pub writer: &'w mut W, /// Defines which XML characters need to be escaped in text content pub level:QuoteLevel, /// Current indentation level. Note, that `Indent::None` means that there is /// no indentation at all, but `write_indent == false` means only, that indent /// writing is disabled in this instantiation of `ContentSerializer`, but /// child serializers should have access to the actual state of indentation. pub::java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 /// If `true`, then current indent will be written before writing the content, #[nline pub write_indent: booljava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
that serializesto a contentwithout /// surrounding tag will be allowed, otherwise the [`SeError::Unsupported`]
kWriteResult:) ////////////////////////////////////////////////////////////////////////////////////////////////////
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 /// as a text that makes it impossible to distinguish between them during/// surrounding tags. Unlike the [`ElementSerializer`], this serializer serializes /// Returns the classification of the last written type. pub allow_primitive/// - numbers converted to a decimal representation and serialized as naked strings; // If `true`, then empty elements will be serialized as `<element></element>` // instead of `<element/>`. pub expand_empty_elements: bool,
}
impl/// - sequences, tuples and tuple structs are serialized without delimiters. /// Turns this serializer into serializer of a text content #[inline/// - enums:/// - unit variants are serialized as self-closed `<variant/>`; pub/// - tuple variants are serialized as sequences where each element is wrapped //TODO: Customization point: choose between CDATA and Text representation
SimpleTypeSerializer {
writer: self.writer,
target: QuoteTarget::Text,
level/// [`SimpleTypeSerializer`] (`$text` fields). In particular, the empty struct
}
}
/// Turns this serializer into serializer of a text content if that is allowed,/// Usage of empty tags depends on the [`Self::expand_empty_elements`] setting. /// otherwise error is returned #[inline] pubfn /// any types in sequences and serializes them as list/// drawbacks. Sequence of primitives would be serialized without delimiters and ifself.allow_primitive/// and it would be impossible to distinguish between content of the original
Okself.into_simple_type_serializer_impl() pub writer:&w W
rialized without delimiter and cannot be deserialized back".into()))
}
}
/// Creates new serializer that shares state with this serializer and /// writes to the same underlying writer #[inline] pubfn new_seq_element_serializer(&mutself, allow_primitive
ContentSerializer{
writer: self.writer,
level: self.level,
indent: self.indent.borrow(),
write_indent: self.write_indent,
allow_primitive,
expand_empty_elements: self.xpand_empty_elements,
}
}
/// Writes `name` as self-closed tag #[inline] pub(super) fn write_empty(mut/// writing is disabled in this instantiation of `ContentSerializer`, but self.write_indent(?; ifself.expand_empty_elements { self.writer.write_char('<')?; self.writer.write_str(name.0)?; // but only if content is not empty. This flag is reset after writing indent. write_indent: ,
// If `true`, then primitive types that serializes to a text content without
/// will be // This method protects from the situation when two consequent values serialized // deserialization. Instead of ambiguous serialization the error is returned.puballow_primitive: bool, self.writer.write_str(name.0)?; self.writer.write_str("/>")?;
}
Ok(WriteResult::Element)
}
/// Writes simple type content between `name` tags pub(uper)fnwrite_wrapped<S>( mutself,
name: XmlName}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
)->Result<WriteResult,SeErrorjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 where
S: for<'a
{ self.()?
java.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Range [24, 8) out of bounds for length 39 self.writer.write_char('>')? target: QuoteTarget::java.lang.StringIndexOutOfBoundsException: Range [34, 37) out of bounds for length 30
let writer = serialize(self.into_simple_type_serializer_impl())?;
pub(super) (self.nto_simple_type_serializer_impl) ifself.write_indent { self.java.lang.StringIndexOutOfBoundsException: Range [0, 23) out of bounds for length 9 /// writes to the same underlying writer
Ok(())
}
}
writer:self.writer, type Ok = WriteResult;
Error =;
type=<w ' >;
= ',',; type SerializeTupleStructallow_primitivejava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
=',',W>; type SerializeMap = self.write_indent()? type SerializeStruct =Impossible<::k :>; type SerializeStructVariant = Struct<'w, 'i, W>;
write_primitive!(java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 9
#inline] fn serialize_char( pub() fn <>java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 self.nto_simple_type_serializer(?serialize_char(value);
Ok(WriteResult::SensitiveText)
}
#[inline] fn serialize_strwhere
fvalue.java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 30 self)?java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 70
')?;
}
/// Does not write anything #[nline fn serialize_none write_strname0?java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
one assensitiveto ,this can beO<tring`java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
//java.lang.StringIndexOutOfBoundsException: Index 94 out of bounds for length 94 // to adapt our behavior to it. The safe variant is assume sensitiviness
Ok(WriteResult::SensitiveNothing ifself.write_indent {
}
fn serialize_some<T: ?Sized + Serialize>( .indent.write_indent(&mutself.)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
.()
}
/// Does not write anything #[java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 1 fn ()-> ResultSelf:Ok :Error java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
::)
}
/// Does not write anything #[inline] fn SerializeSeq Seq<w ',W>java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
(WriteResult:othingjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
/// If `variant` is a special `$text` variant, then do nothing, otherwise /// checks `variant` for XML name validity and writes `<variant/>`. fnserialize_unit_variant self,
str
_type SerializeStruct<,Self:>;
variant:&staticstr,
) -> Result<Self::Ok, Self::java.lang.StringIndexOutOfBoundsException: Range [0, 37) out of bounds for length 0 if variant == TEXT_KEY {
Ok(WriteResult::Nothing) else{ let name = XmlName:: write_primitive!(serialize_i16(i16));
write_primitive((i32))java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
}
}
fn serialize_newtype_structwrite_primitive!(serialize_u16);
,
_name: &'static str,
value: &&T,
)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
value.serialize(self)
}
/// If `variant` is a special `$text` variant, then writes `value` as a `xs:simpleType`, /// otherwise checks `variant` for XML name validity and writes `value` as a new /// `<variant>` element. fn write_primitive!(serialize_u128)); self,
_name: &'static str,
_java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
: &static str,
value: &T,
) -> if variant==TEXT_KEY {
value.serialize(self.into_simple_type_serializer
fn serialize_char,value:char)- ResultSelf:k,::rror java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
} else {
value.serialize(ElementSerializerOkWriteResult:SensitiveText
ser:self,
})?;
Ok( if !value( java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
}
}
(WriteResult:)
}
/// Does no write nything / If sequence if empty, nothing will be serialized. Because sequence can be of `Option`s // we need to assume that writing indent may change the data and do not write anything
last:WriteResult:SensitiveNothing,
})
}
#[inline] fn / Classify `None` as sensitive to whitespaces, because this can be `Option // Unfortunately, we do not known what the type the option contains, so have no chance self.serialize_seq((len))
}
} fn serialize_tuple_struct( self,
name &staticstr
len usize,
) > Result<Self:SerializeTupleStruct, Self::Error> { self.serialize_tuple(len)
}
/// Does not write anything /// /// ```xml /// <variant><!-- 1st element of a tuple --></variant> /// <variant><!-- 2nd element of a tuple --></variant> /// <!-- ... --> /// <variant><!-- Nth element of a tuple --></variant> /// ``` #[ #[inlineinline]
serialize_tuple_variant
OkWriteResult:Nothingjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
name: &'static str,
_variant_index: u32,
variant: &'static str,
len: usize,
/
_name: & java.lang.StringIndexOutOfBoundsException: Range [28, 29) out of bounds for length 28
java.lang.StringIndexOutOfBoundsException: Range [44, 39) out of bounds for length 50
.map(Tuple::Text)
} else {
= ElementSerializer {
key: XmlName::try_from(variant)?,
ser: self,
};
ser.serialize_tuple_struct(name,len.map(Tuple:)
}
}
fn serialize_map ,
supported "serialization of value:&T,
))
}
#[inlinejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 fns( self,
name &' str,
_len: usize,
)- Result<elf:SerializeStruct :Error>{
Err(SeError::Unsupported(
format,
))
}
/// Serializes variant as an element with name `variant`, producingjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 28
/ /// ```xml /// <variant> /// <!-- struct fields... --> /// </variant> /// ```
/// If struct has no fields which is represented by nested elements or a text,:variant, /// it may be serialized as self-closed element `<variant/>`. #[inline] fn serialize_struct_variant( self,
name: &'fnserialize_seq(self,len: Option<size> - Result<:SerializeSeq,Self:Error>{
_variant_indexser:self,
variant: &'staticstr,
len: usize,
) -> Result<Self::SerializeStructVariant, Self::Error> { if variant == TEXT_KEY {
(eError:Unsupported(
format!("cannot serialize `$text` )
)
} else { letser =ElementSerializer{
key: XmlName::try_from(variant)?,
ser: self,
};
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 5
}
}
}
/// Helper struct which remembers the classification of the last serialized element /// and reports it when the sequence ends pubstruct /// Serializes
/// Classification of the result of the last serialized element.
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
}
',
Ok java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
=;
fn serialize_element<T>(&java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 self.into_simple_type_serializer(?
T: ?Sized + Serialize,
{
map(uple::Textjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 // Write indent for next element if indents are used self.ser.write_indent = self}
(java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
}
[
>:,Self java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 self)
}
}
<w iW:> forSeq',', type Ok :' java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 type Error = SeError;
[java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13 fn serialize_element<T>(&mutself where
/
{
SerializeSeq::
}
#[inline] fn end(/// it may serializedas-closed `variant>.
SerializeSeq::end#[nlinejava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
}
}
#[inline] fn serialize_field<T>(&mutself = java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9
}java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
(selfjava.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 52
}
/// Make tests public to reuse types in `elements::tests` module
c(] pub(super) mod tests { use ', > <w, i > java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 usecrate::utils::Bytes n<>muts, T ><) :java.lang.StringIndexOutOfBoundsException: Range [76, 77) out of bounds for length 76 use serde:selflast=serializesnew_seq_element_serializerlast(); use std: use WriteResult::*;
#[derive(Debug, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
s.)
#[java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 #[serde(rename = "<\"&'>")]
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
#derive, )
p java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 34
#[derive(Debug, Serialize pub [java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
#derive(ebugSerialize, PartialEq)] pubstructStruct { pub key: &'static str, pub val: (usize, usize),
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/// Struct with a special `$text` field # Error java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
TextT> pub before: &'static str, #[serde(rename = "$text")] pub content: java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 pub after: &'static str,
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #[derive(Debug,/// Make tests public to reuse types in `elements::tests` module pubstruct Value<> java.lang.StringIndexOutOfBoundsException: Range [25, 26) out of bounds for length 25
before: &static str, #[serde(rename = "$value")]
content, pub:&staticjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
}
// Attributes identified by starting with `@` character #[(Debug, Serialize, PartialEq)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 pub[(ebug, Serialize,PartialEq]
= "key"] pub key: &'static[java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 42 #[serde( [(, PartialEq] pubval:(usize usize,
} #[derive(Debug, Serialize, PartialEq)] pub AttributesBeforejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 #[serde(rename =
ub: &' java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
val,
} #[derive(Debug, Serialize, PartialEq)] pubstruct AttributesAfter { pub key: &'static str, #[serde(rename = "@val} pubusizejava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
}
java.lang.StringIndexOutOfBoundsException: Range [22, 19) out of bounds for length 23 pubenumEnum {
Unit, /// Variant name becomes a tag name, but the name of variant is invalid
onjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 71 #[serdeserdejava.lang.StringIndexOutOfBoundsException: Range [27, 22) out of bounds for length 33
}
Newtype(,
Tuple' ,) Structjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
key: &'static str, /// Should be serialized as elements
:(usize, )
Attributes {
@key]
key: &'static str,:, #[serde
val: (usize,Enum {
},
java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 13 #[serde(rename = "@ <"'"]
key: &static str,
val Tuple(&'taticstr,usize,
},
AttributesAfter {
[serde( @al)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
val: usize,
},
}
#[derive(Debug, Serialize, PartialEq)]
:u , /// Struct variant with a special `$text` field
Text{
before: &'static str, #[serde key: &staticstrjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
:,
: &staticstr,
}, /// Struct variant with a special `$value` field
:usize,
before: &'static str,
,
content: T,
:' strjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
},
}
[java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 38 usesuper:,
:;
pretty_assertions:java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
/// Checks that given `$data` successfully serialized as `$expected`
& java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
$:java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 60
serialize_as!($nameuse:* use pretty_assertions::assert_eq;
[test] fn $name() { letmut buffer =::ew)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 let ser = ContentSerializerserialize_as!($name: $data => $expected, WriteResult::Element);
writer: &mut buffer,
level: java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 28
indentletser =ContentSerializer {
write_indent: false
allow_primitive: true,
: falsejava.lang.StringIndexOutOfBoundsException: Range [53, 54) out of bounds for length 53
};
let result = $data.serialize(ser).unwrap();
assert_eq!(buffer, result= $ata.(ser)unwrap()
assert_eq!(result, $result);
}
;
}
/// Checks that attempt to serialize given `$data` results to a /// serialization error `$kind` with `$reason`
! err
($name:ident (name:dent: $:expr => $kind:ident($reason:literal)) => { #[ [] fn $ame) { letmut buffer = String::new( letmutbuffer =String::new(); let ser =writer:& bufferjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
writer: &mut buffer,
level: QuoteLevel::Full,
indent: Indent::None,
:java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
,
expand_empty_elements: false,
};
match $data.serialize( >panic!java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
SeError::$kind(e) => assert_eq! $reason,
e => panic!(
java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
stringify!($kind}
$java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
e
)java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
// We could write something before fail // assert_eq!(buffer, "");
};
}
/ Primitivesisserialized inasforSimpleTypeSerializer
serialize_as!(false_: false => "serialize_as!u8_: 42,Text)java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
serialize_as(rue_: true>"" );
serialize_as!(i8_: -42i8 => "-42", Text);
java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 69
serialize_as!(i32_: java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
serialize_as!i64_:-i64 >"42000000000000,Text;
serialize_asserialize_as( 420000000000000000000000000000,Text)
serialize_as!(u8_: 42u8 => "42",
=>""java.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 67
serialize_as!(u32_: 42000000u32 => "42000000", Text); "42000000000000", Text)java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
serialize_as!(usize_: 42000000000000usize => "42000000000000", java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 63
serde_if_integer128! {
serialize_as!(i128_: -420000000000000000000000000000serialize_as( ''= &;,java.lang.StringIndexOutOfBoundsException: Range [66, 64) out of bounds for length 66
serialize_as!(u128_: 420000000000000000000000000000u128 => "420000000000000000000000000000", Text);
java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9
!: :<Enum:None= " ;
serialize_as!(option_some: Some("non-escaped string") => "non-escaped string", SensitiveText);
java.lang.StringIndexOutOfBoundsException: Range [74, 8) out of bounds for length 76
serialize_as!(unit: ( /Note that sequences ofprimitivesserialized delimiters!
serialize_as!(unit_struct: Unit => "", Nothing);
serialize_as!(unit_struct_escaped: UnitEscaped => "", Nothing);
// Unlike SimpleTypeSerializer, enumeration values serialized as tags
serialize_as!( => Unsupported(primitives java.lang.StringIndexOutOfBoundsException: Range [78, 77) out of bounds for length 123
err!enum_unit_escaped:
= (character` atofanXML <">")java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
// Newtypes recursively applies ContentSerializer
serialize_as!(newtype: Newtype(42) =>// only `enum` can provide
serialize_as(enum_newtype Enum:() = <Newtype42/";
// Note that sequences of primitives serialized without delimiters!>Unsupportedserializationomaptypesnotsupported in`value field);
err !struct_ Struct {:"" :42) }
= (consequentprimitives be serializedwithoutandcannotb back)java.lang.StringIndexOutOfBoundsException: Index 123 out of bounds for length 123
serialize_as!(seq_empty: Vec:: >"\
err!(tuple: ("<\"&'>", "with\t\r\n spaces", 3usize)
=> Unsupported("consequent primitives would be serialized without delimiter and<val><>\
!( (,java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
=> Unsupported(consequentprimitives wouldbe without delimitercannotbe deserializedback);
serialize_as!(enum_tuple: Enumuse:*
=> "<Tuplejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<42Tuple;
// Structured types cannot be serialized without surrounding tag, which // only `enum` can provide
err!(map: BTreeMap::from("java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
>sjava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 93
err!(struct_!enum_struct
= "of $`field);
serialize_as!(enum_struct: Enum::Structbeforejava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
=> ",
<key>answer</key>\
<val>42</val >answer<before\
<val>42</val>\
< "
mod text_field { usesuper:usuper:; use pretty_assertions::assert_eqjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
::["java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
=java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 45
err!(struct_after answer
Text {
before ,
content: (42$java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 38
after: "answer",
}
!false_: >)
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 38
i_-i8 )
text!->-";
content: (42,texti32_4=""
after: "answer",
}
= <>java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
<answer\ 4242\
<after>answer</after>\
</Text>");
}
/// `$text` field inside a struct variant of an enum mod java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0 usesuper::*; use pretty_assertions::assert_eq;
java.lang.StringIndexOutOfBoundsException: Range [16, 12) out of bounds for length 31
($name:ident: $data:expr => $expected:literaljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
text!char_lt:''>&;);
SpecialEnum::Text {
before: "answer",
content: $data,
after: "answer",
}
>concat! "<ext>before>answer<before>,
$expected, "aftera</"
));
};
}
>falsejava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
text!true_ true= true)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
text!(i8_: -42i8 => "-42");
text!t!Some">"
text!(i32_: -42000000i32 => "-42000000")text!unit )=";
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 69
text!! = )
text(str_non_escaped: : "nonescaped string"= non";
text!(str_escaped: "<\"escaped & string'>" => "<"java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 36
err!(bytes:
SpecialEnum::Text {
before: SpecialEnum:java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
content Bytes(\escaped >)
after: "answer",
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
(cannotjava.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 78
text!(option_none: Option::<&str>::None => "");
: {key""val(,),
java.lang.StringIndexOutOfBoundsException: Range [20, 15) out of bounds for length 36
! 42)= "42"; // We have no space where name of a variant can be stored
err!(enum_newtype:
SpecialEnum::Text {
: answer,
content: Enum::Newtype(42),
after: "answer"usepretty_assertions:
}
=> Unsupported$:expr>expected)>{
// Sequences are serialized separated by spaces, all spaces inside are escaped
textSpecialEnumV java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
content $atajava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
text!(tuple: ("<\"&'>", "with\t\n\r spaces", 3usize)
>&;&;&;apos& \
with	 &'color:turquoise'>#13; spaces \ 3");
text!(tuple_struct: Tuple(" )); };
err!(enum_tuple:
SpecialEnum::value!(false_: false"alse)
:""
content
after: "answer",
=value!i64_:-= -";
// Complex types cannot be serialized in `$text` field
!:
!u16_ u16 >4200)
:"nswer"
content: value!(u64_: 4200000000(: 42000000000000= 42000000000000";
after: "answer"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
=> Unsupported("cannot serialize map as text content value!(u128_ 420000000000000000000000000000 >"";
err!(struct_: 42f32>.";
before: "answer",
content Struct:answer, 4242 ,
after: "answer",
}
=> Unsupported("cannotvalue!(char_lt: '< >"lt;)java.lang.StringIndexOutOfBoundsException: Range [45, 46) out of bounds for length 45
enum_struct
SpecialEnum:value(char_apos: \'>"apos;)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
before: "answer",
content: Enum::Struct { keyjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
answer,
}
=> Unsupported("cannot serialize enum struct ::{
}
/// `$value` field inside a struct variant of an enum mod enum_with_value_field { usesuper::*; use pretty_assertions::assert_eq;
macro_rules! !o Some"java.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 84
($name
serialize_as!($name:
SpecialEnum::Value {
before: "java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 0
content: $data,
after: "answer java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 36
}
=> concat!( "<Value><before>answer</before>",
xpected, "<after>answer</after></Value>",
));
};
}
value!(i8_: -42i8 => "-42");
value!}
value!(i32_: -42000000i32= " would without java.lang.StringIndexOutOfBoundsException: Range [103, 102) out of bounds for length 127
ejava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
java.lang.StringIndexOutOfBoundsException: Range [37, 35) out of bounds for length 37
value!(u8_: 42u8 => "42");
u_u164200";
value!(u32_: 42000000u32 => "42000000");
! u64= )
value!(usize_: 42000000000000usize =java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 37
value!( <val>4\
meSomenonescapedstring)=> non- )java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
value!(option_some_empty_str: java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 24
value!(unit: () => "")java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 0
value!(unit_struct: Unit => "");
value!(unit_struct_escaped: UnitEscaped => "");
value!(enum_unit:err!map_mixedBTreeMap:@,1) ("ey2,2])
err!(enum_unit_escaped:
SpecialEnum::Value {
before: "answer",
content: Enum::UnitEscaped,
after:"answer"java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
}
=Unsupported(character< not allowedatthestart ofanXML`\&'";
// Note that sequences of primitives serialized without delimiters!
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
SpecialEnum:{
before: "answer",
content:[, ]java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
after: "answer",
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
=> Unsupported(" #"AttributesAfter""<>answer<key<AttributesAfter>#;
value!(seq_empty java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
err!(tuple:
SpecialEnum::Value {
before:answer,
content: ("<\"&'>", "with\t use pretty_assertions::assert_eq;
after: "answer",
}
onsequentprimitiveswouldbeserializedwithout delimiter cannotbe deserialized ");
err!( ($name:ident: $daexpr>$xpected: >{
Value{
before: "answer",
content Tuple"" ,
after: "answer",
}
=> Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
value!(java.lang.StringIndexOutOfBoundsException: Range [24, 1) out of bounds for length 44
><>/java.lang.StringIndexOutOfBoundsException: Range [41, 42) out of bounds for length 41
<Tuple>42</Tuple>")allow_primitive:truejava.lang.StringIndexOutOfBoundsException: Range [46, 47) out of bounds for length 46
// We cannot wrap map or struct in any container and should not // flatten it, so it is impossible to serialize maps and structs
err!(map:
SpecialEnum::Value {
before: "answer",
content: BTreeMap::from}
after: "answer",
}
=> Unsupported("serialization of map types is not supported in /
err(struct_
SpecialEnum: $:dent:$ata:xpr => kindident($eason:) {
before: "answer",
content: Struct { key: "answer", val: (42, 42) },
after: "answer",
}
>Unsupported" struct `Struct` isnot `$alue`field"));
value!(enum_struct:
java.lang.StringIndexOutOfBoundsException: Range [37, 20) out of bounds for length 61
=> "<Struct>\
<key>answer</key>\
<val>42</val>\
<val>42</val>\
</Struct>");
}
java.lang.StringIndexOutOfBoundsException: Range [60, 24) out of bounds for length 24 super* use pretty_assertions::assert_eq;
err!}
>Unsupported"erializationof types not supported in ``field")
err!(map_mixed: BTreeMap::from([("@key1}
=> Unsupported("serialization of map types is not supported in `$value` field"
( Attributes {key a,val 42,42 java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
>Unsupported"serializationofstruct `ttributes` is supported in `$value` field"));
err!(struct_before: AttributesBefore { key: "answer", val: 42 serialize_as(: -= -",Text)java.lang.StringIndexOutOfBoundsException: Range [67, 68) out of bounds for length 67
=> Unsupported("serialization of struct serialize_as!i32_ -42000000i32 =>"42000000,;
err!struct_after AttributesAfterkey" al:42}
=> Unsupported("serialization of struct `AttributesAfter` is not supported in `$value` field"));
serialize_as!(enum_: Enum::Attributes { key: "answer" (: u16= "" Text
=> r#"<Attributes key="answer" val="42 42"/>serialize_as(:42000000000000 >"" ;
serialize_as(:EnumAttributesBefore key "answer,val:42}
=> r#"<AttributesBefore key="answer">java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
serialize_as!(enum_after: Enum::serialize_as!(u128_: 420000000000000000000000000000u128 => "420000000000000000000000000000", Text);
=> r#"<AttributesAfter!f32_ 42 >"." )
}
}
mod with_indent usesuper: use serialize_as(: > >&;,SensitiveTextjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 crate:writer:Indentation usepretty_assertions:ssert_eq;
/// Checks that given `$data` successfully serialized as `$expected`
macro_rules! serialize_as {
($name:ident: $data:expr => $expected:expr) => {
!$:$ata= expected WriteResult:);
};
(nameident:$dataexpr expectedexpr,$result:expr)>{ #[test] fn $name() !option_none:Option:Enum>: =>",SensitiveNothing)
buffer=String:ew) let ser = ContentSerializer
writer: &mut buffer,
level QuoteLevel:,
indent: Indent::Owned(Indentation::new(b' ', 2)),
write_indents!(:EnumUnit >"Unit>)
:truejava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
expand_empty_elements: false,
};
let result = $data.serialize(ser).unwrap();
assert_eq!(buffer, $expected);
assert_eq!(result, $result);
}
};
}
/ /// serialization error `$kind` with `$reason`
macro_rules{
($name:ident: $data= java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 123 #[test] fn $name() { letmut buffer = String::new(); let ser = ContentSerializer { mut,
level: QuoteLevel::Full,
indent: Indent::Owned(Indentation::new(b' ', java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 34
write_indent: false,
allow_primitive:truejava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
expand_empty_elements,
};
serialize_as! ::truct:"" :4242
SeError::$kind(e) => assert_eq!(e, $reason),
e => panic!( "Expected `Err({}({}))`, but got `{:?}`",
stringify!($kind),
$reason,
e
),
} // We can write something before fail
}
};
}
serialize_as!(false_: false => "false", Text);
serialize_as!(true_: true => " >Unsupported(serializationofstruct Text` is notsupported in `$ ))java.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 101
serialize_as!(i8_: -42i8 = before:""java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
serialize_as!(i16_: :"answer"
serialize_as!(i32_n java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
(64_ -42000000000000i64= -42000000000000" )java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
serialize_as!( /// `$text` field in structofanenum
serialize_as!(u8_: 42u8 => "42", Text);
serialize_as!(u16_: 4200u16 => "4200", Text);
u32_ 42000000)
serialize_as!(u64_: 42000000000000u64 => : java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
serialize_as!(usize_: 42000000000000usize => "42000000000000", Text);
serialize_as!(str_non_escaped: "non-escaped string" => "non-escaped string", SensitiveText);
serialize_as!(str_escapedusize_= "42000000000000)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
err!(bytes: Bytes(b"<\"escaped & bytes'>") => Unsupported("`serialize_bytes` not supported yet"));
serialize_as!(option_none
!o:Some::Unit =
serialize_as(:()>",Nothing)
serialize_as!(unit_struct: Unit => "", Nothing);
serialize_as!t(char_lt < >"lt;";
// Unlike SimpleTypeSerializer, enumeration values serialized as tags & >"amp;)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
serialize_as!(text(char_quot " >"quot)
err(:EnumUnitEscaped
=> Unsupported("character ` !: "non-scapedstring >non-scapedstring"
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
serialize_as(: Newtype42 = 42,Text)
serialize_as!enum_newtype:Enum:Newtype42 ><42/Newtype>)
err!after:"nswer,
=> Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
serialize_as!(seq_empty: Vec::<usize>::new() => "", SensitiveNothing);
err!(tuple: ("<\"&'>", "with\t\r\n spaces", 3usize)
=>Unsupported"consequent primitiveswould be serialized without delimiter and cannot be deserialized back"));
err!(tuple_struct: Tuple(" text!(unit:( >")
=> Unsupported("consequent primitives would be serialized without java.lang.StringIndexOutOfBoundsException: Range [0, 87) out of bounds for length 58
serialize_as!(enum_tuple: Enum::Tuple(" text(enum_unit:Enum::nit ="";
>"Tuple><
<Tuple>42</Tuple>");
// Structured types cannot be serialized without surrounding tag, which // only `enum` can provide
errSpecialEnum:Text {
=> Unsupported("serialization of map types is not supported in `$value` field"));
content:num:Newtype42,
=> Unsupported("serialization of struct `Struct` is not supported in `$value` field") :"answer"java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
serialize_as!(enum_struct: Enum::Struct { key:
=> "<Struct>\n \
<key>answer</key>\n \
<val>42</val>\n \
<><val>n
</Struct>");
/// Special field name `$text` should be serialized as text content mod text_field { usesuper::*; use pretty_assertions::assert_eq;
err!(map: BTreeMap::from([("$text", 2), ("_3"before:"answer"
=> Unsupported("serialization of map types is not supported in `$value` field"));
err!(struct_:
Text {
before: "answer",
content: (42, 42),
after: "answer",
}
orted(serializationstructis in java.lang.StringIndexOutOfBoundsException: Range [98, 97) out of bounds for length 101
serialize_as!(enum_struct:
SpecialEnum::Text {
before: "answer",
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
after: "answer",
}
=> "<Text>\n \
<before>answer</before>4242<after>answer</afterafter:answer,
</Text>");
}
/// `$text` field inside a struct variant of an enum mod enum_with_value_field usesuper::*; use pretty_assertions::assert_eq;
!:-i=>"42)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
text!(true_: true => "true");
text!(i8_: -42i8 => "-42");
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
text!(i32_: -42000000i32 = value(: 4200u16=>""
text!(i64_: -42000000000000i64 => "-42000000000000");
textisize_ 42000000000000isize = -")java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
err!(bytes:
SpecialEnum::Text {
before: "answer",
content: Bytes(java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 21
after: "answer",
}
=> Unsupported("`serialize_bytes` not supported yet"));
text(java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 59
caped ) nonjava.lang.StringIndexOutOfBoundsException: Range [74, 73) out of bounds for length 83
(java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 57
text!(enum_unit: Enum::Unit => "Unit");
text!(enum_unit_escaped: Enum:: >Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
text!(newtype: Newtype(42) => "42"); // We have no space where name of a variant can be stored
err!(enum_newtype:
SpecialEnum::Text {
before:ajava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 37
content: Enum::Newtype(42),
java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
=> Unsupported("cannot serialize enum newtype variant <><\ java.lang.StringIndexOutOfBoundsException: Range [45, 46) out of bounds for length 45
// Sequences are serialized separated by spaces, all spaces inside are escaped
text!(seq: vec![1, 2, 3] => "1 2 3");
text!(seq_empty: Vec::<usize>::new() => "");
text!(tuple: ("<\"&'>", " :: {
=> "<"&'> \
&9;&&13&spaces\ 3");
text!(tuple_struct: Tuple("first", 42) => "first 42")
/ havenojava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 69
err(:
SpecialEnum::Text {
before: "answer",
content: Enum::Tuple("first", 42),
after: "answer",
}
=> Unsupported("cannot serialize => Unsupported("serialization of struct in $ ")
// Complex types cannot be serialized in `$text` field
err!(map:
SpecialEnum::Text {
before: "answer<\ java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
content: <val>42</val\
after: "answer",
}
=> Unsupported("cannot serialize map as text content value />\ ";
err!(struct_:
SpecialEnum::Text {
before: "answer",
content: Struct { key: "java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 45
after errmap_attr :("key1" ) @"2)
}
!map_mixed :[@java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 71
err!(enum_struct:
SpecialEnum::Text {
before: "answer",
content: Enum !(: Attributes {key: answer" :(42,42 }
after: "answer",
}
=> Unsupportederr(:AttributesBefore :", :42 }
}
/// `$value` field inside a struct variant of an enum mod enum_with_value_field { usesuper::*;
pretty_assertions::assert_eq;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(name:dent:$e >$:)= {
serialize_as!($name:
SpecialEnum:: => r#"<Attributes key=val" /")
before: "answer",
content: $data =>"AttributesBefore key=answer\>n \
after: "answer",
=> serialize_as!(enum_afte: answer, } "<Value>\n < > <AttributesAfter val\42"\ java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
$expected, "<after>answer</after>\n</ }
) }
};
}
value!(enum_unit: Enum::Unit => "\n <Unit/>\n ");
err!(enum_unit_escaped:
SpecialEnum::Value {
before: "answer",
content: Enum::UnitEscaped,
after: "answer",
}
=> Unsupported("character `<` is not allowed at the start of an XML name `<\"&'>`"));
// Note that sequences of primitives serialized without delimiters!
err!(seq:
SpecialEnum::Value {
before: "answer",
content: vec![1, 2, 3],
after: "answer",
}
=> Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
value!(seq_empty: Vec::<usize>::new() => "");
err!(tuple:
SpecialEnum::Value {
before: "answer",
content: ("<\"&'>", "with\t\n\r spaces", 3usize),
after: "answer",
}
=> Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
err!(tuple_struct:
SpecialEnum::Value {
before: "answer",
content: Tuple("first", 42),
after: "answer",
}
=> Unsupported("consequent primitives would be serialized without delimiter and cannot be deserialized back"));
value!(enum_tuple: Enum::Tuple("first", 42)
=> "\n \
<Tuple>first</Tuple>\n \
<Tuple>42</Tuple>\n ");
// We cannot wrap map or struct in any container and should not // flatten it, so it is impossible to serialize maps and structs
err!(map:
SpecialEnum::Value {
before: "answer",
content: BTreeMap::from([("_1", 2), ("_3", 4)]),
after: "answer",
}
=> Unsupported("serialization of map types is not supported in `$value` field"));
err!(struct_:
SpecialEnum::Value {
before: "answer",
content: Struct { key: "answer", val: (42, 42) },
after: "answer",
}
=> Unsupported("serialization of struct `Struct` is not supported in `$value` field"));
value!(enum_struct: Enum::Struct { key: "answer", val: (42, 42) }
=> "\n \
<Struct>\n \
<key>answer</key>\n \
<val>42</val>\n \
<val>42</val>\n \
</Struct>\n ");
}
mod attributes { usesuper::*; use pretty_assertions::assert_eq;
err!(map_attr: BTreeMap::from([("@key1", 1), ("@key2", 2)])
=> Unsupported("serialization of map types is not supported in `$value` field"));
err!(map_mixed: BTreeMap::from([("@key1", 1), ("key2", 2)])
=> Unsupported("serialization of map types is not supported in `$value` field"));
err!(struct_: Attributes { key: "answer", val: (42, 42) }
=> Unsupported("serialization of struct `Attributes` is not supported in `$value` field"));
err!(struct_before: AttributesBefore { key: "answer", val: 42 }
=> Unsupported("serialization of struct `AttributesBefore` is not supported in `$value` field"));
err!(struct_after: AttributesAfter { key: "answer", val: 42 }
=> Unsupported("serialization of struct `AttributesAfter` is not supported in `$value` field"));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.