this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at ca3bd8a72896cb643e1eaf1668581fc7ef1febe7 66 lines 1.9 kB view raw
1use std::io; 2use std::path::Path; 3 4pub struct CmprssCommonArgs { 5 pub compress: bool, 6 pub extract: bool, 7 pub input: Option<String>, 8 pub output: Option<String>, 9} 10 11/// Common interface for all compressor implementations 12#[allow(unused_variables)] 13pub trait Compressor { 14 /// Name of this Compressor 15 fn name(&self) -> &str; 16 17 /// Default extension for this Compressor 18 fn extension(&self) -> &str { 19 self.name() 20 } 21 22 /// Generate the default name for the compressed file 23 fn default_compressed_filename(&self, in_path: &Path) -> String { 24 format!( 25 "{}.{}", 26 in_path.file_name().unwrap().to_str().unwrap(), 27 self.extension() 28 ) 29 } 30 31 // Generate the default extracted filename 32 fn default_extracted_filename(&self, in_path: &Path) -> String { 33 in_path.file_stem().unwrap().to_str().unwrap().to_string() 34 } 35 36 /// Getter method for the common arguments 37 // TODO: There is probably a cleaner way to do this? 38 fn common_args(&self) -> &CmprssCommonArgs; 39 40 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> { 41 cmprss_error("compress_target unimplemented") 42 } 43 44 fn extract(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> { 45 cmprss_error("extract_target unimplemented") 46 } 47} 48 49pub fn cmprss_error(message: &str) -> Result<(), io::Error> { 50 Err(io::Error::new(io::ErrorKind::Other, message)) 51} 52 53/// Defines the possible inputs of a compressor 54// TODO: Implement fmt for CmprssInput/CmprssOutput 55pub enum CmprssInput<'a> { 56 /// Path(s) to the input files. 57 Path(Vec<&'a Path>), 58 /// Input pipe 59 Pipe(std::io::Stdin), 60} 61 62/// Defines the possible outputs of a compressor 63pub enum CmprssOutput<'a> { 64 Path(&'a Path), 65 Pipe(std::io::Stdout), 66}