Skip to content
Snippets Groups Projects
Commit cb5ec8c0 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

decodable implementations

parent 0de75185
Branches
Tags
No related merge requests found
...@@ -37,7 +37,7 @@ pub trait Decoder { ...@@ -37,7 +37,7 @@ pub trait Decoder {
} }
pub trait Decodable: Sized { pub trait Decodable: Sized {
fn decode<T, D>(decoder: &D) -> Result<T, DecoderError> where D: Decoder; fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder;
} }
pub trait View<'a, 'view>: Sized { pub trait View<'a, 'view>: Sized {
......
...@@ -312,19 +312,27 @@ impl<'a> Decoder for BasicDecoder<'a> { ...@@ -312,19 +312,27 @@ impl<'a> Decoder for BasicDecoder<'a> {
} }
impl<T> Decodable for T where T: FromBytes { impl<T> Decodable for T where T: FromBytes {
fn decode<R, D>(decoder: &D) -> Result<R, DecoderError> where D: Decoder { fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
unimplemented!() decoder.read_value(| bytes | {
Ok(try!(T::from_bytes(bytes)))
})
} }
} }
impl<T> Decodable for Vec<T> where T: Decodable { impl<T> Decodable for Vec<T> where T: Decodable {
fn decode<R, D>(decoder: &D) -> Result<R, DecoderError> where D: Decoder { fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
unimplemented!() decoder.read_list(| decoders | {
decoders.iter().map(|d| T::decode(d)).collect()
})
} }
} }
impl Decodable for Vec<u8> { impl Decodable for Vec<u8> {
fn decode<R, D>(decoder: &D) -> Result<R, DecoderError> where D: Decoder { fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
unimplemented!() decoder.read_value(| bytes | {
let mut res = vec![];
res.extend(bytes);
Ok(res)
})
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment