mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Adapt to xso change
This commit is contained in:
parent
ffd0c3c719
commit
5c129d5285
2 changed files with 13 additions and 19 deletions
|
@ -221,9 +221,7 @@ impl TryFrom<Element> for Field {
|
||||||
field.desc = Some(element.text());
|
field.desc = Some(element.text());
|
||||||
} else if element.is("validate", ns::XDATA_VALIDATE) {
|
} else if element.is("validate", ns::XDATA_VALIDATE) {
|
||||||
if field.validate.is_some() {
|
if field.validate.is_some() {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::Other("More than one validate element in field.").into());
|
||||||
"More than one validate element in field.",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
field.validate = Some(Validate::try_from(element.clone())?);
|
field.validate = Some(Validate::try_from(element.clone())?);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -11,6 +11,7 @@ use std::fmt::{Display, Formatter};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use minidom::{Element, IntoAttributeValue};
|
use minidom::{Element, IntoAttributeValue};
|
||||||
|
use xso::error::FromElementError;
|
||||||
|
|
||||||
use crate::ns::XDATA_VALIDATE;
|
use crate::ns::XDATA_VALIDATE;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
@ -178,7 +179,7 @@ pub struct Validate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Element> for Validate {
|
impl TryFrom<Element> for Validate {
|
||||||
type Error = Error;
|
type Error = FromElementError;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Self, Self::Error> {
|
fn try_from(elem: Element) -> Result<Self, Self::Error> {
|
||||||
check_self!(elem, "validate", XDATA_VALIDATE);
|
check_self!(elem, "validate", XDATA_VALIDATE);
|
||||||
|
@ -195,18 +196,18 @@ impl TryFrom<Element> for Validate {
|
||||||
_ if child.is("list-range", XDATA_VALIDATE) => {
|
_ if child.is("list-range", XDATA_VALIDATE) => {
|
||||||
let list_range = ListRange::try_from(child.clone())?;
|
let list_range = ListRange::try_from(child.clone())?;
|
||||||
if validate.list_range.is_some() {
|
if validate.list_range.is_some() {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::Other(
|
||||||
"Encountered unsupported number (n > 1) of list-range in validate element.",
|
"Encountered unsupported number (n > 1) of list-range in validate element.",
|
||||||
));
|
).into());
|
||||||
}
|
}
|
||||||
validate.list_range = Some(list_range);
|
validate.list_range = Some(list_range);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let method = Method::try_from(child.clone())?;
|
let method = Method::try_from(child.clone())?;
|
||||||
if validate.method.is_some() {
|
if validate.method.is_some() {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::Other(
|
||||||
"Encountered unsupported number (n > 1) of validation methods in validate element.",
|
"Encountered unsupported number (n > 1) of validation methods in validate element.",
|
||||||
));
|
).into());
|
||||||
}
|
}
|
||||||
validate.method = Some(method);
|
validate.method = Some(method);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +253,7 @@ impl TryFrom<Element> for Method {
|
||||||
check_no_children!(elem, "regex");
|
check_no_children!(elem, "regex");
|
||||||
Method::Regex(elem.text())
|
Method::Regex(elem.text())
|
||||||
}
|
}
|
||||||
_ => return Err(Error::ParseError("Encountered invalid validation method.")),
|
_ => return Err(Error::Other("Encountered invalid validation method.").into()),
|
||||||
};
|
};
|
||||||
Ok(method)
|
Ok(method)
|
||||||
}
|
}
|
||||||
|
@ -279,9 +280,10 @@ impl FromStr for Datatype {
|
||||||
let mut parts = s.splitn(2, ":");
|
let mut parts = s.splitn(2, ":");
|
||||||
|
|
||||||
let Some(prefix) = parts.next() else {
|
let Some(prefix) = parts.next() else {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::Other(
|
||||||
"Encountered invalid validation datatype which is missing a prefix.",
|
"Encountered invalid validation datatype which is missing a prefix.",
|
||||||
));
|
)
|
||||||
|
.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
match prefix {
|
match prefix {
|
||||||
|
@ -300,9 +302,7 @@ impl FromStr for Datatype {
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(datatype) = parts.next() else {
|
let Some(datatype) = parts.next() else {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::Other("Encountered invalid validation datatype.").into());
|
||||||
"Encountered invalid validation datatype.",
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let parsed_datatype = match datatype.to_ascii_lowercase().as_str() {
|
let parsed_datatype = match datatype.to_ascii_lowercase().as_str() {
|
||||||
|
@ -319,11 +319,7 @@ impl FromStr for Datatype {
|
||||||
"short" => Datatype::Short,
|
"short" => Datatype::Short,
|
||||||
"string" => Datatype::String,
|
"string" => Datatype::String,
|
||||||
"time" => Datatype::Time,
|
"time" => Datatype::Time,
|
||||||
_ => {
|
_ => return Err(Error::Other("Encountered invalid validation datatype.").into()),
|
||||||
return Err(Error::ParseError(
|
|
||||||
"Encountered invalid validation datatype.",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(parsed_datatype)
|
Ok(parsed_datatype)
|
||||||
|
|
Loading…
Reference in a new issue