move in_dir into impl
parent
64abb2b46e
commit
da496e7110
|
@ -1,8 +1,8 @@
|
|||
use std::path::Path;
|
||||
use zettel;
|
||||
use zettel::*;
|
||||
|
||||
fn main() {
|
||||
match zettel::in_dir(Path::new("demo")) {
|
||||
match Zettel::in_dir(Path::new("demo")) {
|
||||
Ok(zettels) => println!(
|
||||
"{}",
|
||||
zettels
|
||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -11,19 +11,6 @@ pub struct Zettel {
|
|||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
// TODO: this could maybe be an iterator?
|
||||
pub fn in_dir(directory: &Path) -> Result<Vec<Zettel>> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(directory)? {
|
||||
out.push(Zettel {
|
||||
path: entry?.path(),
|
||||
})
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
impl fmt::Debug for Zettel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Zettel").field("path", &self.path).finish()
|
||||
|
@ -31,6 +18,19 @@ impl fmt::Debug for Zettel {
|
|||
}
|
||||
|
||||
impl Zettel {
|
||||
// TODO: this could maybe be an iterator?
|
||||
pub fn in_dir(directory: &Path) -> Result<Vec<Zettel>> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(directory)? {
|
||||
out.push(Zettel {
|
||||
path: entry?.path(),
|
||||
})
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
// TODO: is this the most efficient way to do this?
|
||||
// TODO: this mixes the logic of reading a file and parsing the first line. Separate!
|
||||
pub fn title(self: &Zettel) -> Result<String> {
|
||||
|
|
Reference in New Issue