diff --git a/Cargo.lock b/Cargo.lock index 693373e..39c3f34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,5 +3,5 @@ version = 4 [[package]] -name = "rustlog" +name = "outline-rs" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ca814f4..f138594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,9 @@ [package] -name = "rustlog" +name = "outline-rs" version = "0.1.0" edition = "2024" [dependencies] -[[bin]] -name = "rustlog" -path = "main.rs" +[lib] + diff --git a/blocktree.rs b/src/blocktree.rs similarity index 76% rename from blocktree.rs rename to src/blocktree.rs index 3be2920..daa7b25 100644 --- a/blocktree.rs +++ b/src/blocktree.rs @@ -4,15 +4,15 @@ use std::collections::HashMap; #[derive(Debug)] pub struct NoteBlock { // IDs are int64 as this is the datatype of rowids in sqlite - id: i64, - first_child_id: Option, - next_sibling_id: Option, + id: i128, + first_child_id: Option, + next_sibling_id: Option, content: String } impl NoteBlock { - pub fn new(id: i64, first_child_id: Option, next_sibling_id: Option, content: String) -> Self { + pub fn new(id: i128, first_child_id: Option, next_sibling_id: Option, content: String) -> Self { Self {id, first_child_id, next_sibling_id, content} } } @@ -21,14 +21,14 @@ impl NoteBlock { struct BlockTreeNode { // a tree of nodes, where each node refers to its block by id. // the id is used as the key in a page's block table. - block_id: i64, + block_id: i128, block_level: Option, first_child_node: Option>, next_sibling_node: Option> } impl BlockTreeNode { - pub fn new(block_id: i64) -> Self { + pub fn new(block_id: i128) -> Self { BlockTreeNode { block_id, block_level: None, @@ -41,14 +41,14 @@ impl BlockTreeNode { #[derive(Debug)] pub struct NotePage { title: String, - id: i64, + id: i128, block_tree_root: BlockTreeNode, - block_table: HashMap + block_table: HashMap } impl NotePage { - pub fn new(title: String, id: i64, root_block: NoteBlock) -> Self { + pub fn new(title: String, id: i128, root_block: NoteBlock) -> Self { let mut new_page = Self { title, id, @@ -86,3 +86,23 @@ impl NotePage { } } } + +struct NotePageIterator { + page: &NotePage, + node_stack: Vec<&BlockTreeNode> +} + +impl NotePageIterator { + fn new(page: +} + +impl Iterator for NotePageIterator { + type Item = NoteBlock; + fn next(&mut self) -> Option { + // no existing iteration state, initialize with root node + if let None = self.iter_state { + + } + } + +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7953cf0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod blocktree; diff --git a/main.rs b/src/main.rs similarity index 91% rename from main.rs rename to src/main.rs index 20e32da..937570e 100644 --- a/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -mod blocktree; -use crate::blocktree::{NoteBlock, NotePage}; + +use outline_rs::blocktree::{NoteBlock, NotePage}; fn main() { let root_block = NoteBlock::new(0,Some(1),Some(2),String::from("hello"));