server_info: Implement Default and use it.

This commit is contained in:
Emmanuel Gil Peyrot 2019-03-20 19:10:01 +01:00
parent cbc787a9d4
commit 00e19012e5

View file

@ -9,7 +9,7 @@ use crate::util::error::Error;
use try_from::TryFrom; use try_from::TryFrom;
/// Structure representing a `http://jabber.org/network/serverinfo` form type. /// Structure representing a `http://jabber.org/network/serverinfo` form type.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Default)]
pub struct ServerInfo { pub struct ServerInfo {
/// Abuse addresses /// Abuse addresses
pub abuse: Vec<String>, pub abuse: Vec<String>,
@ -40,14 +40,7 @@ impl TryFrom<DataForm> for ServerInfo {
if form.form_type != Some(String::from(ns::SERVER_INFO)) { if form.form_type != Some(String::from(ns::SERVER_INFO)) {
return Err(Error::ParseError("Wrong FORM_TYPE for form.")); return Err(Error::ParseError("Wrong FORM_TYPE for form."));
} }
let mut server_info = ServerInfo { let mut server_info = ServerInfo::default();
abuse: vec![],
admin: vec![],
feedback: vec![],
sales: vec![],
security: vec![],
support: vec![],
};
for field in form.fields { for field in form.fields {
if field.type_ != FieldType::ListMulti { if field.type_ != FieldType::ListMulti {
return Err(Error::ParseError("Field is not of the required type.")); return Err(Error::ParseError("Field is not of the required type."));