macro_rules! impl_builder_mandatory_string_attr {
($arg:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.[<set_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$arg = $arg.into();
}
}
};
($arg:ident, $alt:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.[<set_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$arg = $arg.into();
}
}
};
}
macro_rules! impl_builder_mandatory_string_attr_delegated {
($arg:ident, $del:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$del.$arg = $arg.into();
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$del.$arg = $arg.into();
}
}
};
($arg:ident, $alt:ident, $del:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$del.$arg = $arg.into();
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$del.$arg = $arg.into();
}
}
};
}
macro_rules! impl_builder_mandatory_attr {
($arg: ident, $t: ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.$arg = $arg;
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
self.$arg = $arg;
}
}
};
($arg: ident, $alt:ident, $t: ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.$arg = $arg;
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
self.$arg = $arg;
}
}
};
}
macro_rules! impl_builder_mandatory_attr_delegated {
($arg: ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.$del.$arg = $arg;
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
self.$del.$arg = $arg;
}
}
};
($arg: ident, $alt:ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.$del.$arg = $arg;
self
}
#[doc = concat!("Re-set the mandatory attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
self.$del.$arg = $arg;
}
}
};
}
macro_rules! impl_builder_opt_string_attr {
($arg:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$arg = Some($arg.into());
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$arg = Some($arg.into());
}
}
};
($arg:ident, $alt:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$arg = Some($arg.into());
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$arg = Some($arg.into());
}
}
};
}
macro_rules! impl_builder_opt_string_attr_delegated {
($arg:ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$del.$arg = Some($arg.into());
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$del.$arg = Some($arg.into());
}
}
};
($arg:ident, $alt:ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>]<I: Into<String>>(mut self, $arg: I) -> Self {
self.$del.$arg = Some($arg.into());
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>]<I: Into<String>>(&mut self, $arg: I) {
self.$del.$arg = Some($arg.into());
}
}
};
}
macro_rules! impl_builder_opt_attr {
($arg: ident, $t: ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.$arg = Some($arg);
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
self.$arg = Some($arg);
}
}
};
($arg: ident, $alt:ident, $t: ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.$arg = Some($arg);
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
self.$arg = Some($arg);
}
}
};
}
macro_rules! impl_builder_opt_attr_delegated {
($arg: ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.[<set_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
self.$del.$arg = Some($arg);
}
}
};
($arg: ident, $alt:ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.[<set_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional attribute `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
self.$del.$arg = Some($arg);
}
}
};
}
macro_rules! impl_builder_opt_subelem {
($arg: ident, $t: ident) => {
paste! {
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.[<set_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
if self.$arg.replace($arg).is_some() {
warn!(concat!("Multiple occurrence of ", stringify!($arg), ". All but the last one are discarded."));
}
}
#[doc = concat!("Reset the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<reset_ $arg>](mut self, $arg: $t) -> Self {
self.[<reset_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Reset the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<reset_ $arg _by_ref>](&mut self, $arg: $t) {
let _ = self.$arg.replace($arg);
}
}
};
($arg: ident, $alt:ident, $t: ident) => {
paste! {
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.[<set_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
if self.$arg.replace($arg).is_some() {
warn!(concat!("Multiple occurrence of ", stringify!($arg), ". All but the last one are discarded."));
}
}
#[doc = concat!("Reset the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<reset_ $alt>](mut self, $arg: $t) -> Self {
self.[<reset_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Reset the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<reset_ $alt _by_ref>](&mut self, $arg: $t) {
let _ = self.$arg.replace($arg);
}
}
};
}
macro_rules! impl_builder_opt_subelem_delegated {
($arg: ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $arg>](mut self, $arg: $t) -> Self {
self.[<set_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $arg _by_ref>](&mut self, $arg: $t) {
if self.$del.$arg.replace($arg).is_some() {
warn!(concat!("Multiple occurrence of ", stringify!($arg), ". All but the last one are discarded."));
}
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<reset_ $arg>](mut self, $arg: $t) -> Self {
self.[<reset_ $arg _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<reset_ $arg _by_ref>](&mut self, $arg: $t) {
let _ = self.$del.$arg.replace($arg);
}
}
};
($arg: ident, $alt:ident, $t: ident, $del:ident) => {
paste! {
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<set_ $alt>](mut self, $arg: $t) -> Self {
self.[<set_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
if self.$del.$arg.replace($arg).is_some() {
warn!(concat!("Multiple occurrence of ", stringify!($arg), ". All but the last one are discarded."));
}
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` taking the ownership and returning itself.")]
pub fn [<reset_ $alt>](mut self, $arg: $t) -> Self {
self.[<reset_ $alt _by_ref>]($arg);
self
}
#[doc = concat!("Set the optional sub-element `", stringify!($arg), "` by mutable ref.")]
pub fn [<set_ $alt _by_ref>](&mut self, $arg: $t) {
let _ = self.$del.$arg.replace($arg);
}
}
};
}
macro_rules! impl_has_content {
($tag:ident) => {
paste! {
impl HasContent for $tag {
fn get_content(&self) -> Option<&str> {
self.content.as_deref()
}
fn set_content<S: Into<String>>(mut self, content: S) -> Self {
self.content = Some(content.into());
self
}
fn set_content_by_ref<S: Into<String>>(&mut self, content: S) {
self.content = Some(content.into());
}
}
}
};
}
macro_rules! impl_builder_push_elem {
($t: ident, $e: expr) => {
paste! {
#[doc = concat!("Add the given `", stringify!($e), "` to the element list.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given `", stringify!($e), "` to the element list, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.elems.push($e::$t([<$t:lower>]));
}
}
};
($t: ident, $e: expr, $a: ident) => {
paste! {
#[doc = concat!("Add the given `", stringify!($a), "` to the element list.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $a) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given `", stringify!($a), "` to the element list, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $a) {
self.elems.push($e::$t([<$t:lower>]));
}
}
};
}
macro_rules! impl_builder_push_boxed_elem {
($t: ident, $e: expr) => {
paste! {
#[doc = concat!("Add the given `", stringify!($e), "` to the element list.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given `", stringify!($e), "` to the element list, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.elems.push($e::$t(Box::new([<$t:lower>])));
}
}
};
($t: ident, $e: expr, $a: ident) => {
paste! {
#[doc = concat!("Add the given `", stringify!($a), "` to the element list.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $a) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given `", stringify!($a), "` to the element list, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $a) {
self.elems.push($e::$t([<$t:lower>]));
}
}
};
}
macro_rules! impl_builder_push {
($t: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.[<$t:lower s>].push([<$t:lower>]);
}
}
};
($t: ident, $c: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t<$c>) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t<$c>) {
self.[<$t:lower s>].push([<$t:lower>]);
}
}
};
}
macro_rules! impl_builder_prepend {
($t: ident) => {
paste! {
#[doc = concat!("Prepend the given object to the list of `", stringify!($t), "`.")]
pub fn [<prepend_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<prepend_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Prepend the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<prepend_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.[<$t:lower s>].insert(0, [<$t:lower>]);
}
}
};
($t: ident, $c: ident) => {
paste! {
#[doc = concat!("Prepend the given object to the list of `", stringify!($t), "`.")]
pub fn [<prepend_ $t:lower>](mut self, [<$t:lower>]: $t<$c>) -> Self {
self.[<prepend_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Prepend the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<prepend_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t<$c>) {
self.[<$t:lower s>].insert(0, [<$t:lower>]);
}
}
};
}
macro_rules! impl_builder_push_delegated {
($t: ident, $del: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.$del.[<$t:lower s>].push([<$t:lower>]);
}
}
};
($t: ident, $c: ident, $del: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t<$c>) -> Self {
self.[<push_ $t:lower _by_ref>]([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t<$c>) {
self.$del.[<$t:lower s>].push([<$t:lower>]);
}
}
};
}
#[cfg(feature = "mivot")]
macro_rules! impl_builder_push_no_s {
($t: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t) -> Self {
self.[<$t:lower>].push([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t) {
self.[<$t:lower>].push([<$t:lower>]);
}
}
};
($t: ident, $c: ident) => {
paste! {
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`.")]
pub fn [<push_ $t:lower>](mut self, [<$t:lower>]: $t<$c>) -> Self {
self.[<$t:lower>].push([<$t:lower>]);
self
}
#[doc = concat!("Add the given object to the list of `", stringify!($t), "`, by mutable ref.")]
pub fn [<push_ $t:lower _by_ref>](&mut self, [<$t:lower>]: $t<$c>) {
self.[<$t:lower>].push([<$t:lower>]);
}
}
};
}
macro_rules! impl_builder_push_post_info {
() => {
#[doc = concat!("Add the given info to the list of post infos.")]
pub fn push_post_info(mut self, info: Info) -> Self {
self.push_post_info_by_ref(info);
self
}
#[doc = concat!("Add the given info to the list of post infos, by mutable ref.")]
pub fn push_post_info_by_ref(&mut self, info: Info) {
self.post_infos.push(info);
}
};
}
macro_rules! impl_builder_insert_extra {
() => {
pub fn insert_extra<S: Into<String>>(mut self, key: S, value: Value) -> Self {
self.insert_extra_by_ref(key, value);
self
}
pub fn insert_extra_by_ref<S: Into<String>>(&mut self, key: S, value: Value) {
let mut key = key.into();
if !key.as_str().contains(':') {
key = format!("extra:{}", &key);
}
self.extra.insert(key, value);
}
pub fn insert_extra_str<S: Into<String>, T: Into<String>>(mut self, key: S, value: T) -> Self {
self.insert_extra_by_ref(key, Value::String(value.into()));
self
}
pub fn insert_extra_str_by_ref<S: Into<String>, T: Into<String>>(&mut self, key: S, value: T) {
self.insert_extra_by_ref(key, Value::String(value.into()))
}
};
}
macro_rules! impl_builder_insert_extra_delegated {
($del:ident) => {
pub fn insert_extra<S: Into<String>>(mut self, key: S, value: Value) -> Self {
self.insert_extra_by_ref(key, value);
self
}
pub fn insert_extra_by_ref<S: Into<String>>(&mut self, key: S, value: Value) {
let mut key = key.into();
if !key.as_str().contains(':') {
key = format!("extra:{}", &key);
}
self.$del.extra.insert(key, value);
}
pub fn insert_extra_str<S: Into<String>, T: Into<String>>(mut self, key: S, value: T) -> Self {
self.insert_extra_by_ref(key, Value::String(value.into()));
self
}
pub fn insert_extra_str_by_ref<S: Into<String>, T: Into<String>>(&mut self, key: S, value: T) {
self.insert_extra_by_ref(key, Value::String(value.into()))
}
};
}
macro_rules! write_opt_string_attr {
($self:ident, $elem_writer:ident, $arg:ident) => {
paste! {
if let Some([<$arg:lower>]) = $self.[<$arg:lower>].as_ref() {
$elem_writer = $elem_writer.with_attribute((stringify!($arg), [<$arg:lower>].as_str()));
}
}
};
($self:ident, $elem_writer:ident, $arg:ident, $arg_str:literal) => {
paste! {
if let Some([<$arg:lower>]) = $self.[<$arg:lower>].as_ref() {
$elem_writer = $elem_writer.with_attribute(($arg_str, [<$arg:lower>].as_str()));
}
}
};
}
macro_rules! write_opt_tostring_attr {
($self:ident, $elem_writer:ident, $arg:ident) => {
paste! {
if let Some([<$arg:lower>]) = $self.[<$arg:lower>].as_ref() {
$elem_writer = $elem_writer.with_attribute((stringify!($arg), [<$arg:lower>].to_string().as_str()));
}
}
};
($self:ident, $elem_writer:ident, $arg:ident, $arg_str:literal) => {
paste! {
if let Some([<$arg:lower>]) = $self.[<$arg:lower>].as_ref() {
$elem_writer = $elem_writer.with_attribute(($arg_str, [<$arg:lower>].to_string().as_str()));
}
}
};
}
macro_rules! for_each_extra_attribute {
($self:ident, $f:ident) => {
for (k, v) in &$self.extra {
match v {
Value::Null => $f(k.as_str(), ""),
Value::Bool(v) => $f(k.as_str(), v.to_string().as_str()),
Value::Number(v) => $f(k.as_str(), v.to_string().as_str()),
Value::String(v) => $f(k.as_str(), v.to_string().as_str()),
Value::Array(_) => $f(k.as_str(), v.to_string().as_str()),
Value::Object(_) => $f(k.as_str(), v.to_string().as_str()),
}
}
};
}
macro_rules! for_each_extra_attribute_delegated {
($self:ident, $del:ident, $f:ident) => {
for (k, v) in &$self.$del.extra {
match v {
Value::Null => $f(k.as_str(), ""),
Value::Bool(v) => $f(k.as_str(), v.to_string().as_str()),
Value::Number(v) => $f(k.as_str(), v.to_string().as_str()),
Value::String(v) => $f(k.as_str(), v.to_string().as_str()),
Value::Array(_) => $f(k.as_str(), v.to_string().as_str()),
Value::Object(_) => $f(k.as_str(), v.to_string().as_str()),
}
}
};
}
macro_rules! write_elem {
($self:ident, $elem:ident, $writer:ident, $context:ident) => {
if let Some(elem) = &mut $self.$elem {
elem.write($writer, $context)?;
}
};
}
macro_rules! write_elem_vec {
($self:ident, $elems:ident, $writer:ident, $context:ident) => {
for elem in &mut $self.$elems {
elem.write($writer, $context)?;
}
};
}
macro_rules! write_elem_vec_no_context {
($self:ident, $elems:ident, $writer:ident) => {
for elem in &mut $self.$elems {
elem.write($writer)?;
}
};
}
macro_rules! write_elem_vec_empty_context {
($self:ident, $elems:ident, $writer:ident) => {
for elem in &mut $self.$elems {
elem.write($writer, &())?;
}
};
}
macro_rules! from_event_start_by_ref {
($elem:ident, $reader:ident, $reader_buff:ident, $e:ident) => {{
$elem::from_event_start($e)
.and_then(|elem| elem.read_content(&mut $reader, &mut $reader_buff, &()))?
}};
($elem:ident, $reader:ident, $reader_buff:ident, $e:ident, $context:expr) => {{
$elem::from_event_start($e)
.and_then(|elem| elem.read_content(&mut $reader, &mut $reader_buff, &$context))?
}};
}
macro_rules! set_from_event_start {
($self:ident, $elem:ident, $reader:ident, $reader_buff:ident, $e:ident) => {
paste! {
$elem::from_event_start($e)
.and_then(|elem| elem.read_content($reader, $reader_buff, &()))
.map(|elem| $self.[<set_ $elem:lower _by_ref>](elem))?
}
};
($self:ident, $elem:ident, $reader:ident, $reader_buff:ident, $e:ident, $context:expr) => {
paste! {
$elem::from_event_start($e)
.and_then(|elem| elem.read_content($reader, $reader_buff, &$context))
.map(|elem| $self.[<set_ $elem:lower _by_ref>](elem))?
}
};
}
macro_rules! set_from_event_empty {
($self:ident, $elem:ident, $e:ident) => {
paste! {
$elem::from_event_empty($e)
.map(|elem| $self.[<set_ $elem:lower _by_ref>](elem))?
}
};
}
macro_rules! set_desc_from_event_start {
($self:ident, $reader:ident, $reader_buff:ident, $e:ident) => {
set_from_event_start!($self, Description, $reader, $reader_buff, $e)
};
}
macro_rules! push_from_event_start {
($self:ident, $elem:ident, $reader:ident, $reader_buff:ident, $e:ident) => {
paste! {
$elem::from_event_start($e)
.and_then(|elem| elem.read_content(&mut $reader, &mut $reader_buff, &()))
.map(|elem| $self.[<push_ $elem:lower _by_ref>](elem))?
}
};
($self:ident, $elem:ident, $reader:ident, $reader_buff:ident, $e:ident, $context:expr) => {
paste! {
$elem::from_event_start($e)
.and_then(|elem| elem.read_content(&mut $reader, &mut $reader_buff, &$context))
.map(|elem| $self.[<push_ $elem:lower _by_ref>](elem))?
}
};
}
macro_rules! push_from_event_empty {
($self:ident, $elem:ident, $e:ident) => {
paste! {
$elem::from_event_empty($e)
.map(|elem| $self.[<push_ $elem:lower _by_ref>](elem))?
}
};
}