xmelt 0.2.0

A serialization/deserialization framework for XML
Documentation
use super::*;

pub trait Item: Sized {
	///! Add support for defining the container type into the type system
	type Container/*: Container<Self::Inner>*/;
	type Inner/*: for<'a> Freeze<'a>*/;

	fn from_container(container: <Self as Item>::Container, message: String) -> Result<Self, Error>;

	// fn from_builder(container: <<Self as Item>::Inner as ItemBuilder>::Builder, message: String) -> Result<Self, Error>;
}

impl<T> Item for Option<T> {
	type Container = Self;
	type Inner = T;

	fn from_container(container: <Self as Item>::Container, message: String) -> Result<Self, Error> {
		Ok(container)
	}
}

impl<T> Item for Vec<T> {
	type Container = Self;
	type Inner = T;

	fn from_container(container: <Self as Item>::Container, message: String) -> Result<Self, Error> {
		Ok(container)
	}
}

/*impl Item for String {
	type Container = Self;
	type Inner = Self;

	fn from_container(container: String, message: String) -> Result<Self, Error> {
		if container.len() == 0 {
			Err(Error::MissingValue(message))
		} else {
			Ok(container)
		}
	}
}*/

/*impl<K: std::hash::Hash + std::cmp::Eq, V> Item for std::collections::HashMap<K, V> {
	type Container = Self;
	// type Inner = (K, V);
	type Inner = ();

	fn from_container(container: <Self as Item>::Container, message: String) -> Result<Self, Error> {
		Ok(container)
	}
}*/

impl<'freeze, T> Item for T
	where T: Freeze<'freeze>
{
	type Container = Option<Self>;
	type Inner = Self;

	fn from_container(container: <Self as Item>::Container, message: String) -> Result<Self, Error> {
		container.ok_or_else(|| Error::MissingValue(message))
	}
}

pub trait ItemBuilder<'freeze> {
	type Builder: Builder<'freeze>;
}