-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pt
committed
Apr 16, 2024
1 parent
f03e279
commit 85c1eb2
Showing
13 changed files
with
84 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::Read; | ||
use std::path::Path; | ||
use quick_xml::de; | ||
use zip::read::ZipFile; | ||
use serde::Deserialize; | ||
use zip::ZipArchive; | ||
use crate::xml::content_types::ContentTypes; | ||
use crate::xml::drawings::Drawings; | ||
use crate::xml::metadata::Metadata; | ||
use crate::xml::relationships::Relationships; | ||
use crate::xml::shared_string::SharedString; | ||
use crate::xml::style::StyleSheet; | ||
use crate::xml::workbook::Workbook; | ||
use crate::xml::worksheet::WorkSheet; | ||
|
||
pub(crate) trait Io<T: Default> { | ||
fn from_path<P: AsRef<Path>>(file_path: P) -> io::Result<T>; | ||
fn save<P: AsRef<Path>>(&self, file_path: P); | ||
async fn from_path_async<P: AsRef<Path>>(file_path: P) -> io::Result<T> { | ||
Self::from_path(file_path) | ||
} | ||
async fn save_async<P: AsRef<Path>>(&self, file_path: P) { | ||
self.save(file_path) | ||
} | ||
} | ||
|
||
pub(crate) trait IoV2<T: for<'de> Deserialize<'de>> { | ||
fn from_zip_file(archive: &mut ZipArchive<File>, path: &str) -> Option<T> { | ||
if let Ok(mut file) = archive.by_name(path) { | ||
let mut xml = String::new(); | ||
file.read_to_string(&mut xml).unwrap(); | ||
de::from_str(&xml).ok() | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
fn from_zip_file(file: &mut ZipFile) -> T; | ||
} | ||
impl IoV2<Workbook> for Workbook {} | ||
impl IoV2<WorkSheet> for WorkSheet{} | ||
impl IoV2<StyleSheet> for StyleSheet {} | ||
impl IoV2<ContentTypes> for ContentTypes{} | ||
impl IoV2<Relationships> for Relationships{} | ||
impl IoV2<Metadata> for Metadata{} | ||
impl IoV2<SharedString> for SharedString{} | ||
impl IoV2<Drawings> for Drawings{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.