-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
1 parent
ef3be3e
commit ef6b94c
Showing
4 changed files
with
46 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
|
||
#[derive(Clone, Debug)] | ||
pub(crate) struct Document { | ||
path: String, | ||
data: String, | ||
} | ||
|
||
impl Document { | ||
pub fn from_text_file(path: &PathBuf) -> Result<Self> { | ||
let path = std::fs::canonicalize(path.display().to_string())? | ||
.display() | ||
.to_string(); | ||
let data = std::fs::read_to_string(&path)?; | ||
Ok(Self { path, data }) | ||
} | ||
|
||
pub fn get_path(&self) -> &str { | ||
&self.path | ||
} | ||
|
||
pub fn get_data(&self) -> &str { | ||
&self.data | ||
} | ||
|
||
pub fn get_byte_size(&self) -> usize { | ||
self.data.as_bytes().len() | ||
} | ||
} |
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