You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
723 B
23 lines
723 B
3 years ago
|
//! Conversion operations
|
||
|
use super::*;
|
||
|
use std::io::{
|
||
|
self, Write, Read,
|
||
|
};
|
||
|
use error::Error;
|
||
|
|
||
|
/// Convert from a reader to a writer
|
||
|
/// # Returns
|
||
|
/// The number of bytes read from the `input` stream, and the number of bytes written to the `output` stream.
|
||
|
pub fn conv_reader_writer<R: Read, W: Write>(input: R, input_format: FormatKind, output: W, output_format: FormatKind) -> Result<(usize, usize), Error>
|
||
|
{
|
||
|
let cfg = formats::config::Config::default();
|
||
|
|
||
|
let input_format = input_format.directive();
|
||
|
let output_format = output_format.directive();
|
||
|
|
||
|
let (obj, read) = input_format.call_decode(&cfg, input)?;
|
||
|
let write = output_format.call_encode(&cfg, output, &obj)?;
|
||
|
|
||
|
Ok((read, write))
|
||
|
}
|