···11+use std::path::PathBuf;
22+33+use color_eyre::eyre::Result;
44+55+use crate::types::Workspace;
66+77+/// The `Kasten` that stores the `Link`s between `Zettel`s
88+#[derive(Debug, Clone)]
99+pub struct Kasten {
1010+ /// Private field so it can only be instantiated from a `Path`
1111+ _private: (),
1212+ // / Connection to the sqlite database inside the `Workspace`
1313+ pub ws: Workspace,
1414+}
1515+1616+impl Kasten {
1717+ /// Given a path, try to construct a `Kasten`.
1818+ pub async fn index(root: impl Into<PathBuf>) -> Result<Self> {
1919+ let ws = Workspace::instansiate(root).await?;
2020+2121+ Ok(Self { _private: (), ws })
2222+ }
2323+}
2424+2525+#[cfg(test)]
2626+mod tests {
2727+ use std::{
2828+ fs::{File, create_dir_all},
2929+ path::PathBuf,
3030+ };
3131+3232+ use crate::types::Kasten;
3333+3434+ #[tokio::test]
3535+ async fn test_instantiation() {
3636+ let path = PathBuf::from("/tmp/filaments/.filaments/filaments.db");
3737+ create_dir_all(path.parent().unwrap()).unwrap();
3838+ let _ = File::create(&path).unwrap();
3939+ let _k = Kasten::index(dbg!(&path.parent().unwrap().parent().unwrap()))
4040+ .await
4141+ .unwrap();
4242+ }
4343+}
+3
src/types/mod.rs
···2020mod workspace;
2121pub use workspace::Workspace;
22222323+mod kasten;
2424+pub use kasten::Kasten;
2525+2326mod frontmatter;
2427pub use frontmatter::FrontMatter;
+1-1
src/types/workspace.rs
···8585 let path = PathBuf::from("/tmp/filaments/.filaments/filaments.db");
8686 create_dir_all(path.parent().unwrap()).unwrap();
8787 let _ = File::create(&path).unwrap();
8888- let _ws = Workspace::instansiate(dbg!(&path.parent().unwrap().parent().unwrap()))
8888+ let _k = Workspace::instansiate(dbg!(&path.parent().unwrap().parent().unwrap()))
8989 .await
9090 .unwrap();
9191 }