Stashing
This commit is contained in:
parent
5366d8271d
commit
64267c953b
|
@ -7,4 +7,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
cdtypes = {path = "../cdtypes"}
|
||||
paste = "*"
|
||||
tool_helper = {path = "../tool_helper"}
|
|
@ -1,73 +0,0 @@
|
|||
use super::*;
|
||||
|
||||
pub struct DirectoryIterator<'a> {
|
||||
parent: &'a Directory,
|
||||
state: DirectoryIteratorState<'a>
|
||||
}
|
||||
|
||||
impl<'a> DirectoryIterator<'a> {
|
||||
pub fn new(parent: &Directory) -> DirectoryIterator {
|
||||
DirectoryIterator{parent, state: DirectoryIteratorState::Root}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::iter::Iterator for DirectoryIterator<'a> {
|
||||
type Item = DirectoryIteratorElement<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<DirectoryIteratorElement<'a>> {
|
||||
match std::mem::replace(&mut self.state, DirectoryIteratorState::Done) {
|
||||
DirectoryIteratorState::Root => {
|
||||
self.state = DirectoryIteratorState::Data(self.parent.data.iter());
|
||||
return Some(DirectoryIteratorElement::Directory(&self.parent));
|
||||
}
|
||||
DirectoryIteratorState::Data(mut iter) => {
|
||||
if let Some(data) = iter.next() {
|
||||
self.state = DirectoryIteratorState::Data(iter);
|
||||
return Some(DirectoryIteratorElement::Data(data));
|
||||
}
|
||||
|
||||
else {
|
||||
self.state = DirectoryIteratorState::Directory(self.parent.dirs.iter());
|
||||
return self.next();
|
||||
}
|
||||
},
|
||||
DirectoryIteratorState::Directory(mut iter) => {
|
||||
if let Some(dir) = iter.next() {
|
||||
self.state = DirectoryIteratorState::SubDir((iter, std::boxed::Box::new(dir.iter())));
|
||||
return self.next();
|
||||
}
|
||||
|
||||
else {
|
||||
return self.next();
|
||||
}
|
||||
},
|
||||
DirectoryIteratorState::SubDir((base_iter, mut iter)) => {
|
||||
if let Some(element) = iter.next() {
|
||||
self.state = DirectoryIteratorState::SubDir((base_iter, iter));
|
||||
return Some(element);
|
||||
}
|
||||
|
||||
else {
|
||||
self.state = DirectoryIteratorState::Directory(base_iter);
|
||||
return self.next();
|
||||
}
|
||||
},
|
||||
DirectoryIteratorState::Done => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum DirectoryIteratorState<'a> {
|
||||
Root,
|
||||
Data(std::slice::Iter<'a, Data>),
|
||||
Directory(std::slice::Iter<'a, Directory>),
|
||||
SubDir((std::slice::Iter<'a, Directory>, std::boxed::Box<DirectoryIterator<'a>>)),
|
||||
Done
|
||||
}
|
||||
|
||||
pub enum DirectoryIteratorElement<'a> {
|
||||
Directory(&'a Directory),
|
||||
Data(&'a Data),
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
use super::*;
|
||||
|
||||
pub struct DefaultLayoutMut {
|
||||
}
|
||||
|
||||
impl DefaultLayoutMut {
|
||||
pub fn new(parent: &mut CDDesc) -> Vec<LayoutMut> {
|
||||
let mut layout = Vec::new();
|
||||
|
||||
add_dir_and_subdir(&mut layout, &mut parent.root);
|
||||
layout
|
||||
}
|
||||
}
|
||||
|
||||
pub enum LayoutMut<'a> {
|
||||
Directory{name: &'a mut DirectoryName, properties: &'a mut Properties},
|
||||
Data(&'a mut Data)
|
||||
}
|
||||
|
||||
fn add_dir_and_subdir<'a>(layout: &mut Vec<LayoutMut::<'a>>, dir: &'a mut Directory) {
|
||||
layout.push(LayoutMut::Directory{name: &mut dir.name, properties: &mut dir.properties});
|
||||
for data in dir.data.iter_mut() {
|
||||
layout.push(LayoutMut::Data(data));
|
||||
}
|
||||
|
||||
for dir in dir.dirs.iter_mut() {
|
||||
add_dir_and_subdir(layout, dir);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
use std::fmt::write;
|
||||
pub mod layout;
|
||||
|
||||
use iterator::DirectoryIterator;
|
||||
use cdtypes::types::cdstring::DString;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub mod iterator;
|
||||
pub struct CDDesc {
|
||||
pub root: Directory
|
||||
}
|
||||
|
@ -37,10 +35,6 @@ impl Directory {
|
|||
pub fn add_data(&mut self, data: Data) {
|
||||
self.data.push(data);
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> DirectoryIterator {
|
||||
DirectoryIterator::new(&self)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Directory {
|
||||
|
|
Loading…
Reference in New Issue