diff options
Diffstat (limited to 'librepology/src/v1/buffer.rs')
-rw-r--r-- | librepology/src/v1/buffer.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/librepology/src/v1/buffer.rs b/librepology/src/v1/buffer.rs new file mode 100644 index 0000000..534ab4c --- /dev/null +++ b/librepology/src/v1/buffer.rs @@ -0,0 +1,41 @@ +use std::io::Read; + +use crate::v1::error::Result; +use crate::v1::error::RepologyError as Error; +use crate::v1::types::Problem; +use crate::v1::types::Package; +use crate::v1::api::Api; + +#[derive(Debug)] +pub struct BufferApi { + buf: String, +} + +impl BufferApi +{ + pub fn read_from<R>(mut input: R) -> Result<BufferApi> + where R: Read, + { + let mut buf = String::new(); + let read = input.read_to_string(&mut buf)?; + trace!("Read {} bytes from stdin", read); + Ok(BufferApi { buf }) + } +} + +impl Api for BufferApi { + + fn project<N: AsRef<str>>(&self, _name: N) -> Result<Vec<Package>> { + serde_json::de::from_str(&self.buf).map_err(Error::from) + } + + fn problems_for_repo<R: AsRef<str>>(&self, _repo: R) -> Result<Vec<Problem>> { + serde_json::de::from_str(&self.buf).map_err(Error::from) + } + + fn problems_for_maintainer<M: AsRef<str>>(&self, _maintainer: M) -> Result<Vec<Problem>> { + serde_json::de::from_str(&self.buf).map_err(Error::from) + } + +} + |