2017-04-29 21:14:34 +00:00
|
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
2018-12-18 14:27:30 +00:00
|
|
|
|
use crate::ns;
|
2024-07-24 18:28:22 +00:00
|
|
|
|
use minidom::Element;
|
2024-06-30 07:42:55 +00:00
|
|
|
|
use xso::{
|
|
|
|
|
error::{Error, FromElementError, FromEventsError},
|
|
|
|
|
exports::rxml,
|
|
|
|
|
minidom_compat, AsXml, FromXml,
|
|
|
|
|
};
|
2017-04-29 03:37:18 +00:00
|
|
|
|
|
2018-08-02 18:43:47 +00:00
|
|
|
|
/// Requests paging through a potentially big set of items (represented by an
|
|
|
|
|
/// UID).
|
2020-11-29 20:17:51 +00:00
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2018-08-02 18:35:15 +00:00
|
|
|
|
pub struct SetQuery {
|
|
|
|
|
/// Limit the number of items, or use the recipient’s defaults if None.
|
|
|
|
|
pub max: Option<usize>,
|
|
|
|
|
|
|
|
|
|
/// The UID after which to give results, or if None it is the element
|
|
|
|
|
/// “before” the first item, effectively an index of negative one.
|
2017-04-29 03:37:18 +00:00
|
|
|
|
pub after: Option<String>,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
|
|
|
|
|
/// The UID before which to give results, or if None it starts with the
|
|
|
|
|
/// last page of the full set.
|
2017-04-29 03:37:18 +00:00
|
|
|
|
pub before: Option<String>,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
|
|
|
|
|
/// Numerical index of the page (deprecated).
|
2017-04-29 03:37:18 +00:00
|
|
|
|
pub index: Option<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:35:15 +00:00
|
|
|
|
impl TryFrom<Element> for SetQuery {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
type Error = FromElementError;
|
2017-05-06 19:14:45 +00:00
|
|
|
|
|
2024-06-21 14:27:43 +00:00
|
|
|
|
fn try_from(elem: Element) -> Result<SetQuery, FromElementError> {
|
2018-05-14 14:30:28 +00:00
|
|
|
|
check_self!(elem, "set", RSM, "RSM set");
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let mut set = SetQuery {
|
|
|
|
|
max: None,
|
2017-05-21 14:30:22 +00:00
|
|
|
|
after: None,
|
|
|
|
|
before: None,
|
|
|
|
|
index: None,
|
|
|
|
|
};
|
2017-05-06 19:14:45 +00:00
|
|
|
|
for child in elem.children() {
|
2018-08-02 18:35:15 +00:00
|
|
|
|
if child.is("max", ns::RSM) {
|
|
|
|
|
if set.max.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one max.").into());
|
2018-08-02 18:35:15 +00:00
|
|
|
|
}
|
2024-06-21 14:27:43 +00:00
|
|
|
|
set.max = Some(child.text().parse().map_err(Error::text_parse_error)?);
|
2018-08-02 18:35:15 +00:00
|
|
|
|
} else if child.is("after", ns::RSM) {
|
2017-05-21 14:30:22 +00:00
|
|
|
|
if set.after.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one after.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2017-05-21 14:30:22 +00:00
|
|
|
|
set.after = Some(child.text());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
} else if child.is("before", ns::RSM) {
|
2017-05-21 14:30:22 +00:00
|
|
|
|
if set.before.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one before.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2017-05-21 14:30:22 +00:00
|
|
|
|
set.before = Some(child.text());
|
2018-08-02 18:35:15 +00:00
|
|
|
|
} else if child.is("index", ns::RSM) {
|
|
|
|
|
if set.index.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one index.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2024-06-21 14:27:43 +00:00
|
|
|
|
set.index = Some(child.text().parse().map_err(Error::text_parse_error)?);
|
2018-08-02 18:35:15 +00:00
|
|
|
|
} else {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Unknown child in set element.").into());
|
2018-08-02 18:35:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(set)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 07:42:55 +00:00
|
|
|
|
impl FromXml for SetQuery {
|
|
|
|
|
type Builder = minidom_compat::FromEventsViaElement<SetQuery>;
|
|
|
|
|
|
|
|
|
|
fn from_events(
|
|
|
|
|
qname: rxml::QName,
|
|
|
|
|
attrs: rxml::AttrMap,
|
|
|
|
|
) -> Result<Self::Builder, FromEventsError> {
|
|
|
|
|
if qname.0 != crate::ns::RSM || qname.1 != "set" {
|
|
|
|
|
return Err(FromEventsError::Mismatch { name: qname, attrs });
|
|
|
|
|
}
|
|
|
|
|
Self::Builder::new(qname, attrs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:35:15 +00:00
|
|
|
|
impl From<SetQuery> for Element {
|
|
|
|
|
fn from(set: SetQuery) -> Element {
|
2020-03-28 12:07:26 +00:00
|
|
|
|
Element::builder("set", ns::RSM)
|
2020-04-02 20:45:20 +00:00
|
|
|
|
.append_all(
|
|
|
|
|
set.max
|
|
|
|
|
.map(|max| Element::builder("max", ns::RSM).append(format!("{}", max))),
|
|
|
|
|
)
|
2019-07-24 22:20:38 +00:00
|
|
|
|
.append_all(
|
2018-12-18 14:32:05 +00:00
|
|
|
|
set.after
|
2020-03-28 12:07:26 +00:00
|
|
|
|
.map(|after| Element::builder("after", ns::RSM).append(after)),
|
2019-10-22 23:32:41 +00:00
|
|
|
|
)
|
2024-02-05 23:49:37 +00:00
|
|
|
|
.append_all(set.before.map(|before| {
|
|
|
|
|
let mut builder = Element::builder("before", ns::RSM);
|
|
|
|
|
if !before.is_empty() {
|
|
|
|
|
builder = builder.append(before);
|
|
|
|
|
}
|
|
|
|
|
builder
|
|
|
|
|
}))
|
2020-04-02 20:45:20 +00:00
|
|
|
|
.append_all(
|
|
|
|
|
set.index
|
|
|
|
|
.map(|index| Element::builder("index", ns::RSM).append(format!("{}", index))),
|
|
|
|
|
)
|
2018-12-18 14:32:05 +00:00
|
|
|
|
.build()
|
2018-08-02 18:35:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 07:42:55 +00:00
|
|
|
|
impl AsXml for SetQuery {
|
|
|
|
|
type ItemIter<'x> = minidom_compat::AsItemsViaElement<'x>;
|
|
|
|
|
|
|
|
|
|
fn as_xml_iter(&self) -> Result<Self::ItemIter<'_>, Error> {
|
|
|
|
|
minidom_compat::AsItemsViaElement::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:43:47 +00:00
|
|
|
|
/// Describes the paging result of a [query](struct.SetQuery.html).
|
2020-11-29 20:17:51 +00:00
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2018-08-02 18:35:15 +00:00
|
|
|
|
pub struct SetResult {
|
|
|
|
|
/// The UID of the first item of the page.
|
|
|
|
|
pub first: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// The position of the [first item](#structfield.first) in the full set
|
|
|
|
|
/// (which may be approximate).
|
|
|
|
|
pub first_index: Option<usize>,
|
|
|
|
|
|
|
|
|
|
/// The UID of the last item of the page.
|
|
|
|
|
pub last: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// How many items there are in the full set (which may be approximate).
|
|
|
|
|
pub count: Option<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for SetResult {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
type Error = FromElementError;
|
2018-08-02 18:35:15 +00:00
|
|
|
|
|
2024-06-21 14:27:43 +00:00
|
|
|
|
fn try_from(elem: Element) -> Result<SetResult, FromElementError> {
|
2018-08-02 18:35:15 +00:00
|
|
|
|
check_self!(elem, "set", RSM, "RSM set");
|
|
|
|
|
let mut set = SetResult {
|
|
|
|
|
first: None,
|
|
|
|
|
first_index: None,
|
|
|
|
|
last: None,
|
|
|
|
|
count: None,
|
|
|
|
|
};
|
|
|
|
|
for child in elem.children() {
|
|
|
|
|
if child.is("first", ns::RSM) {
|
2017-05-21 14:30:22 +00:00
|
|
|
|
if set.first.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one first.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2019-02-24 19:48:19 +00:00
|
|
|
|
set.first_index = get_attr!(child, "index", Option);
|
2017-05-21 14:30:22 +00:00
|
|
|
|
set.first = Some(child.text());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
} else if child.is("last", ns::RSM) {
|
2017-05-21 14:30:22 +00:00
|
|
|
|
if set.last.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one last.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2017-05-21 14:30:22 +00:00
|
|
|
|
set.last = Some(child.text());
|
2018-08-02 18:35:15 +00:00
|
|
|
|
} else if child.is("count", ns::RSM) {
|
|
|
|
|
if set.count.is_some() {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Set can’t have more than one count.").into());
|
2017-05-06 19:14:45 +00:00
|
|
|
|
}
|
2024-06-21 14:27:43 +00:00
|
|
|
|
set.count = Some(child.text().parse().map_err(Error::text_parse_error)?);
|
2017-05-06 19:14:45 +00:00
|
|
|
|
} else {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
return Err(Error::Other("Unknown child in set element.").into());
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-21 14:30:22 +00:00
|
|
|
|
Ok(set)
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-03 11:04:56 +00:00
|
|
|
|
impl FromXml for SetResult {
|
|
|
|
|
type Builder = minidom_compat::FromEventsViaElement<SetResult>;
|
|
|
|
|
|
|
|
|
|
fn from_events(
|
|
|
|
|
qname: rxml::QName,
|
|
|
|
|
attrs: rxml::AttrMap,
|
|
|
|
|
) -> Result<Self::Builder, FromEventsError> {
|
|
|
|
|
if qname.0 != crate::ns::RSM || qname.1 != "set" {
|
|
|
|
|
return Err(FromEventsError::Mismatch { name: qname, attrs });
|
|
|
|
|
}
|
|
|
|
|
Self::Builder::new(qname, attrs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:35:15 +00:00
|
|
|
|
impl From<SetResult> for Element {
|
|
|
|
|
fn from(set: SetResult) -> Element {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let first = set.first.clone().map(|first| {
|
2020-03-28 12:07:26 +00:00
|
|
|
|
Element::builder("first", ns::RSM)
|
2018-12-18 14:32:05 +00:00
|
|
|
|
.attr("index", set.first_index)
|
2017-10-31 22:21:50 +00:00
|
|
|
|
.append(first)
|
2018-12-18 14:32:05 +00:00
|
|
|
|
});
|
2020-03-28 12:07:26 +00:00
|
|
|
|
Element::builder("set", ns::RSM)
|
2019-09-06 14:03:58 +00:00
|
|
|
|
.append_all(first)
|
2019-07-24 22:20:38 +00:00
|
|
|
|
.append_all(
|
2018-12-18 14:32:05 +00:00
|
|
|
|
set.last
|
2020-03-28 12:07:26 +00:00
|
|
|
|
.map(|last| Element::builder("last", ns::RSM).append(last)),
|
2018-12-18 14:32:05 +00:00
|
|
|
|
)
|
2020-04-02 20:45:20 +00:00
|
|
|
|
.append_all(
|
|
|
|
|
set.count
|
|
|
|
|
.map(|count| Element::builder("count", ns::RSM).append(format!("{}", count))),
|
|
|
|
|
)
|
2018-12-18 14:32:05 +00:00
|
|
|
|
.build()
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-03 11:04:56 +00:00
|
|
|
|
impl AsXml for SetResult {
|
|
|
|
|
type ItemIter<'x> = minidom_compat::AsItemsViaElement<'x>;
|
|
|
|
|
|
|
|
|
|
fn as_xml_iter(&self) -> Result<Self::ItemIter<'_>, Error> {
|
|
|
|
|
minidom_compat::AsItemsViaElement::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 03:37:18 +00:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
2017-05-06 19:14:45 +00:00
|
|
|
|
use super::*;
|
2017-04-29 03:37:18 +00:00
|
|
|
|
|
2018-10-28 12:10:48 +00:00
|
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_size() {
|
|
|
|
|
assert_size!(SetQuery, 40);
|
|
|
|
|
assert_size!(SetResult, 40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2018-10-26 12:26:16 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_size() {
|
|
|
|
|
assert_size!(SetQuery, 80);
|
|
|
|
|
assert_size!(SetResult, 80);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 03:37:18 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple() {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let set = SetQuery::try_from(elem).unwrap();
|
|
|
|
|
assert_eq!(set.max, None);
|
2017-04-29 03:37:18 +00:00
|
|
|
|
assert_eq!(set.after, None);
|
|
|
|
|
assert_eq!(set.before, None);
|
2018-08-02 18:35:15 +00:00
|
|
|
|
assert_eq!(set.index, None);
|
|
|
|
|
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let set = SetResult::try_from(elem).unwrap();
|
2017-04-29 03:37:18 +00:00
|
|
|
|
match set.first {
|
|
|
|
|
Some(_) => panic!(),
|
|
|
|
|
None => (),
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(set.last, None);
|
2018-08-02 18:35:15 +00:00
|
|
|
|
assert_eq!(set.count, None);
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_unknown() {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2024-03-02 08:19:49 +00:00
|
|
|
|
let error = SetQuery::try_from(elem.clone()).unwrap_err();
|
|
|
|
|
let returned_elem = match error {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
FromElementError::Mismatch(elem) => elem,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
2024-03-02 08:19:49 +00:00
|
|
|
|
assert_eq!(elem, returned_elem);
|
2018-08-02 18:35:15 +00:00
|
|
|
|
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2024-03-02 08:19:49 +00:00
|
|
|
|
let error = SetResult::try_from(elem.clone()).unwrap_err();
|
|
|
|
|
let returned_elem = match error {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
FromElementError::Mismatch(elem) => elem,
|
2017-04-29 03:37:18 +00:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
2024-03-02 08:19:49 +00:00
|
|
|
|
assert_eq!(elem, returned_elem);
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_invalid_child() {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'><coucou/></set>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let error = SetQuery::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown child in set element.");
|
|
|
|
|
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'><coucou/></set>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let error = SetResult::try_from(elem).unwrap_err();
|
2017-04-29 03:37:18 +00:00
|
|
|
|
let message = match error {
|
2024-06-21 14:27:43 +00:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-29 03:37:18 +00:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown child in set element.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_serialise() {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let rsm = SetQuery {
|
|
|
|
|
max: None,
|
2017-04-29 03:37:18 +00:00
|
|
|
|
after: None,
|
|
|
|
|
before: None,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
index: None,
|
|
|
|
|
};
|
|
|
|
|
let elem2 = rsm.into();
|
|
|
|
|
assert_eq!(elem, elem2);
|
|
|
|
|
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'/>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let rsm = SetResult {
|
2017-04-29 03:37:18 +00:00
|
|
|
|
first: None,
|
2017-05-21 14:30:22 +00:00
|
|
|
|
first_index: None,
|
2017-04-29 03:37:18 +00:00
|
|
|
|
last: None,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
count: None,
|
2017-04-29 03:37:18 +00:00
|
|
|
|
};
|
2017-05-23 22:31:33 +00:00
|
|
|
|
let elem2 = rsm.into();
|
2017-04-29 03:37:18 +00:00
|
|
|
|
assert_eq!(elem, elem2);
|
|
|
|
|
}
|
2017-05-21 14:41:16 +00:00
|
|
|
|
|
2024-02-05 23:49:37 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_serialise_empty_before() {
|
|
|
|
|
let elem: Element = "<set xmlns='http://jabber.org/protocol/rsm'><before/></set>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
|
|
|
|
let rsm = SetQuery {
|
|
|
|
|
max: None,
|
|
|
|
|
after: None,
|
|
|
|
|
before: Some("".into()),
|
|
|
|
|
index: None,
|
|
|
|
|
};
|
|
|
|
|
let elem2 = rsm.into();
|
|
|
|
|
assert_eq!(elem, elem2);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 14:41:16 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_first_index() {
|
2018-12-18 14:32:05 +00:00
|
|
|
|
let elem: Element =
|
|
|
|
|
"<set xmlns='http://jabber.org/protocol/rsm'><first index='4'>coucou</first></set>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2017-05-23 22:31:33 +00:00
|
|
|
|
let elem1 = elem.clone();
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let set = SetResult::try_from(elem).unwrap();
|
2017-05-21 14:41:16 +00:00
|
|
|
|
assert_eq!(set.first, Some(String::from("coucou")));
|
|
|
|
|
assert_eq!(set.first_index, Some(4));
|
|
|
|
|
|
2018-08-02 18:35:15 +00:00
|
|
|
|
let set2 = SetResult {
|
2017-05-21 14:41:16 +00:00
|
|
|
|
first: Some(String::from("coucou")),
|
|
|
|
|
first_index: Some(4),
|
|
|
|
|
last: None,
|
2018-08-02 18:35:15 +00:00
|
|
|
|
count: None,
|
2017-05-21 14:41:16 +00:00
|
|
|
|
};
|
2017-05-23 22:31:33 +00:00
|
|
|
|
let elem2 = set2.into();
|
2019-11-29 13:33:17 +00:00
|
|
|
|
assert_eq!(elem1, elem2);
|
2017-05-21 14:41:16 +00:00
|
|
|
|
}
|
2017-04-29 03:37:18 +00:00
|
|
|
|
}
|