Revert "Made Url serde-compatible"
This reverts commit 3cb52a83013e228ed0fd7d33b7cf125607409fd9.
This commit is contained in:
parent
61784a9c55
commit
03884c6ff9
2 changed files with 1 additions and 29 deletions
|
@ -2,7 +2,6 @@ use std::convert::TryFrom;
|
|||
use std::error::Error;
|
||||
|
||||
use url::Url;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::task::Task;
|
||||
use crate::task::TaskId;
|
||||
|
@ -10,7 +9,6 @@ use crate::task::TaskId;
|
|||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SupportedComponents: u8 {
|
||||
/// An event, such as a calendar meeting
|
||||
const EVENT = 1;
|
||||
|
@ -47,10 +45,9 @@ impl TryFrom<minidom::Element> for SupportedComponents {
|
|||
|
||||
|
||||
/// A Caldav Calendar
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Calendar {
|
||||
name: String,
|
||||
#[serde(with="crate::utils::url_serde")]
|
||||
url: Url,
|
||||
supported_components: SupportedComponents,
|
||||
|
||||
|
|
25
src/utils.rs
25
src/utils.rs
|
@ -1,7 +1,6 @@
|
|||
///! Some utility functions
|
||||
|
||||
use minidom::Element;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Walks an XML tree and returns every element that has the given name
|
||||
pub fn find_elems<S: AsRef<str>>(root: &Element, searched_name: S) -> Vec<&Element> {
|
||||
|
@ -51,27 +50,3 @@ pub fn print_xml(element: &Element) {
|
|||
|
||||
writer.write(&[0x0a]);
|
||||
}
|
||||
|
||||
|
||||
/// Used to (de)serialize url::Url
|
||||
pub mod url_serde{
|
||||
use super::*;
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<url::Url, D::Error>
|
||||
where
|
||||
D: serde::de::Deserializer<'de>
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
match url::Url::parse(&s) {
|
||||
Ok(u) => Ok(u),
|
||||
Err(_) => { return Err(serde::de::Error::invalid_value(serde::de::Unexpected::Str(&s), &"Expected an url")); }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize<S>(u: &url::Url, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::ser::Serializer,
|
||||
{
|
||||
serializer.serialize_str( u.as_str() )
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue