Commit 23307a47 authored by François Laignel's avatar François Laignel Committed by Sebastian Dröge

Tags: ser/de: gather tags with the same name together

parent d856fedf
......@@ -93,7 +93,9 @@ impl<'de> Visitor<'de> for FieldVisitor {
.ok_or(de::Error::custom("Expected a value for `Value` name"))?;
let type_name = seq.next_element::<String>()?
.ok_or(de::Error::custom("Expected a value for `Value` type"))?;
Ok(FieldDe(name, de_send_value!(type_name, seq)))
let send_value = de_send_value!(type_name, seq)?
.ok_or(de::Error::custom("Expected a value for `Value`"))?;
Ok(FieldDe(name, send_value))
}
}
......@@ -103,6 +105,7 @@ impl<'de> Deserialize<'de> for FieldDe {
}
}
// FIXME: use DeserializeSeed instead
// Use `NamelessStructure` to deserialize the `Field`s and
// to add them to the `Structure` at the same time.
struct NamelessStructure(Structure);
......
......@@ -39,7 +39,7 @@ macro_rules! impl_tag(
}
lazy_static! {
static ref $rust_tag: &'static str =
pub static ref $rust_tag: &'static str =
unsafe { CStr::from_ptr(ffi::$gst_tag).to_str().unwrap() };
}
};
......
This diff is collapsed.
......@@ -199,7 +199,9 @@ mod tests {
"(",
" scope: Global,",
" tags: Some([",
" (\"title\", \"toc\"),",
" (\"title\", [",
" \"toc\",",
" ]),",
" ]),",
" entries: [",
" (",
......@@ -221,7 +223,9 @@ mod tests {
" uid: \"chapter1.1\",",
" start_stop: Some((0, 4)),",
" tags: Some([",
" (\"title\", \"chapter 1.1\"),",
" (\"title\", [",
" \"chapter 1.1\",",
" ]),",
" ]),",
" loop_: Some((None, 0)),",
" sub_entries: [",
......@@ -232,7 +236,9 @@ mod tests {
" uid: \"chapter1.2\",",
" start_stop: Some((4, 10)),",
" tags: Some([",
" (\"title\", \"chapter 1.2\"),",
" (\"title\", [",
" \"chapter 1.2\",",
" ]),",
" ]),",
" loop_: Some((None, 0)),",
" sub_entries: [",
......@@ -245,7 +251,9 @@ mod tests {
" uid: \"chapter2\",",
" start_stop: Some((10, 15)),",
" tags: Some([",
" (\"title\", \"chapter 2\"),",
" (\"title\", [",
" \"chapter 2\",",
" ]),",
" ]),",
" loop_: Some((None, 0)),",
" sub_entries: [",
......@@ -271,7 +279,7 @@ mod tests {
(
scope: Global,
tags: Some([
("title", "toc"),
("title", ["toc"]),
]),
entries: [
(
......@@ -293,7 +301,7 @@ mod tests {
uid: "chapter1.1",
start_stop: Some((0, 4)),
tags: Some([
("title", "chapter 1.1"),
("title", ["chapter 1.1"]),
]),
loop_: Some((None, 0)),
sub_entries: [
......@@ -304,7 +312,7 @@ mod tests {
uid: "chapter1.2",
start_stop: Some((4, 10)),
tags: Some([
("title", "chapter 1.2"),
("title", ["chapter 1.2"]),
]),
loop_: Some((None, 0)),
sub_entries: [
......@@ -317,7 +325,7 @@ mod tests {
uid: "chapter2",
start_stop: Some((10, 15)),
tags: Some([
("title", "chapter 2"),
("title", ["chapter 2"]),
]),
loop_: Some((None, 0)),
sub_entries: [
......
......@@ -163,32 +163,36 @@ impl_ser_send_value_collection!(Array);
impl_ser_send_value_collection!(List);
macro_rules! de_value(
($outer_type:expr, $type_name:expr, $seq:expr, $t:ty) => (
$seq
.next_element::<$t>()?
.ok_or_else(||
de::Error::custom(format!(
"Expected a value for `{}` with type {:?}",
$outer_type,
$type_name,
))
)?
.to_value()
($seq:expr, $t:ty) => (
{
let value = $seq
.next_element::<$t>()?
.and_then(|base_value| Some(base_value.to_value()));
Ok(value)
}
);
);
macro_rules! de_send_value(
($type_name:expr, $seq:expr, $t:ty) => (
SendValue::from(
de_value!("Value", $type_name, $seq, $t)
.try_into_send_value::<$t>()
.map_err(|_|
de::Error::custom(format!(
"Failed to convert `Value` with type {:?} to `SendValue`",
$type_name,
))
)?
)
de_send_value!("Value", $type_name, $seq, $t)
);
($outer_type:expr, $type_name:expr, $seq:expr, $t:ty) => (
match de_value!($seq, $t)? {
Some(value) => {
let glib_send_value = value
.try_into_send_value::<$t>()
.map_err(|_|
de::Error::custom(format!(
"Failed to convert `{}` with type {:?} to `SendValue`",
$outer_type,
$type_name,
))
)?;
Ok(Some(SendValue::from(glib_send_value)))
}
None => Ok(None)
}
);
($type_name:expr, $seq:expr) => (
match $type_name.as_str() {
......@@ -233,7 +237,9 @@ impl<'de> Visitor<'de> for SendValueVisitor {
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
let type_name = seq.next_element::<String>()?
.ok_or(de::Error::custom("Expected a value for `Value` type"))?;
Ok(de_send_value!(type_name, seq))
let send_value = de_send_value!(type_name, seq)?
.ok_or(de::Error::custom("Expected a value for `Value`"))?;
Ok(send_value)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment