Skip to content

Commit

Permalink
added kind and ext for collected data.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin committed Apr 17, 2018
1 parent 3360f3a commit 8e8ffdf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

pub trait HasKind {

pub trait MsDoc<T>: Read {
// kind
fn kind(&self) -> &'static str;

// extension
fn ext(&self) -> &'static str;
}

pub trait MsDoc<T>: Read + HasKind {
fn open<P: AsRef<Path>>(path: P) -> io::Result<T>;
}

pub trait OpenOfficeDoc<T>: Read {
pub trait OpenOfficeDoc<T>: Read + HasKind {
fn open<P: AsRef<Path>>(path: P) -> io::Result<T>;
}
12 changes: 11 additions & 1 deletion src/docx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

use doc::MsDoc;
use doc::{MsDoc, HasKind};

pub struct Docx {
path: PathBuf,
data: Cursor<String>
}

impl HasKind for Docx {
fn kind(&self) -> &'static str {
"Word Document"
}

fn ext(&self) -> &'static str {
"docx"
}
}

impl MsDoc<Docx> for Docx {

fn open<P: AsRef<Path>>(path: P) -> io::Result<Docx> {
Expand Down
12 changes: 11 additions & 1 deletion src/odp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

use doc::OpenOfficeDoc;
use doc::{OpenOfficeDoc, HasKind};

pub struct Odp {
path: PathBuf,
data: Cursor<String>
}

impl HasKind for Odp {
fn kind(&self) -> &'static str {
"Open Office Presentation"
}

fn ext(&self) -> &'static str {
"odp"
}
}

impl OpenOfficeDoc<Odp> for Odp {

fn open<P: AsRef<Path>>(path: P) -> io::Result<Odp> {
Expand Down
12 changes: 11 additions & 1 deletion src/odt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

use doc::OpenOfficeDoc;
use doc::{OpenOfficeDoc, HasKind};

pub struct Odt {
path: PathBuf,
data: Cursor<String>
}

impl HasKind for Odt {
fn kind(&self) -> &'static str {
"Open Office Document"
}

fn ext(&self) -> &'static str {
"odt"
}
}

impl OpenOfficeDoc<Odt> for Odt {

fn open<P: AsRef<Path>>(path: P) -> io::Result<Odt> {
Expand Down
13 changes: 12 additions & 1 deletion src/pptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

use doc::MsDoc;
use doc::{MsDoc, HasKind};

pub struct Pptx {
path: PathBuf,
data: Cursor<String>
}

impl HasKind for Pptx {
fn kind(&self) -> &'static str {
"Power Point"
}

fn ext(&self) -> &'static str {
"pptx"
}
}

impl MsDoc<Pptx> for Pptx {

fn open<P: AsRef<Path>>(path: P) -> io::Result<Pptx> {
let file = File::open(path.as_ref())?;
let mut archive = ZipArchive::new(file)?;
Expand Down
13 changes: 12 additions & 1 deletion src/xlsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ use std::io;
use std::clone::Clone;
use zip::read::ZipFile;

use doc::MsDoc;
use doc::{MsDoc, HasKind};

pub struct Xlsx {
path: PathBuf,
data: Cursor<String>
}

impl HasKind for Xlsx {
fn kind(&self) -> &'static str {
"Excel"
}

fn ext(&self) -> &'static str {
"xlsx"
}
}

impl MsDoc<Xlsx> for Xlsx {

fn open<P: AsRef<Path>>(path: P) -> io::Result<Xlsx> {
let file = File::open(path.as_ref())?;
let mut archive = ZipArchive::new(file)?;
Expand Down

0 comments on commit 8e8ffdf

Please sign in to comment.