Skip to content

Commit

Permalink
refactor: cargo fix etc
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan committed Feb 18, 2025
1 parent c5799de commit d5b860b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
19 changes: 8 additions & 11 deletions src/components/tree/tree_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ impl<T> TreeNode<T> {

pub fn iter(&self) -> TreeNodeIterator<T> {
// TODO: iter_mut???
let iter = TreeNodeIterator {

TreeNodeIterator {
root: self,
current_node: None,
current_path: TreeNodePath::empty(),
};

iter
}
}
}

Expand Down Expand Up @@ -192,14 +191,12 @@ impl<'a, T> Iterator for TreeNodeIterator<'a, T> {
}
}
}
} else if self.root.children.is_empty() {
None
} else {
if self.root.children.is_empty() {
None
} else {
self.current_path = self.current_path.with_child(0);
self.current_node = Some(&self.root.children[0]);
self.current_node
}
self.current_path = self.current_path.with_child(0);
self.current_node = Some(&self.root.children[0]);
self.current_node
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/cue/cue_line.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{
fmt::{Debug, Display, Formatter},
fs::{read_to_string, File},
io::{self, BufRead, BufReader, Read},
fs::File,
io::{self, BufRead, Read},
path::Path,
};

use log::error;

#[derive(Eq, PartialEq, Debug)]
pub struct CueLine {
pub indentation: usize,
Expand Down
16 changes: 5 additions & 11 deletions src/cue/cue_line_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{collections::VecDeque, rc::Rc};

use crate::cue::cue_line::CueLine;

#[derive(Debug, Eq, PartialEq)]
Expand All @@ -16,8 +14,8 @@ impl CueLineNode {
}
}

pub fn from_lines(mut cue_lines: Vec<CueLine>) -> Vec<CueLineNode> {
fn node_by_depth<'a>(nodes: &'a mut [CueLineNode], depth: usize) -> &'a mut CueLineNode {
pub fn from_lines(cue_lines: Vec<CueLine>) -> Vec<CueLineNode> {
fn node_by_depth(nodes: &mut [CueLineNode], depth: usize) -> &mut CueLineNode {
assert!(!nodes.is_empty());

let node = &mut nodes[nodes.len() - 1];
Expand Down Expand Up @@ -47,7 +45,7 @@ impl CueLineNode {
parent.children.push(node);
} else if node.line.indentation > depth {
// current `node` is a child of previous `node`
let mut parent = node_by_depth(&mut top_nodes, depth);
let parent = node_by_depth(&mut top_nodes, depth);
parent.children.push(node);
depth += 1;
} else {
Expand All @@ -57,7 +55,7 @@ impl CueLineNode {
if depth == 0 {
top_nodes.push(node);
} else {
let mut parent = node_by_depth(&mut top_nodes, depth - 1);
let parent = node_by_depth(&mut top_nodes, depth - 1);
parent.children.push(node);
}
}
Expand Down Expand Up @@ -87,8 +85,6 @@ mod tests {

let file = &cue_nodes[cue_nodes.len() - 1];

println!("{:#?}", file.children[0]);

assert_eq!(
file.line,
CueLine {
Expand Down Expand Up @@ -215,7 +211,7 @@ mod tests {
let path = Path::new("src/cue/Moroccan Roll.cue");
let cue_lines = CueLine::from_file(path).unwrap();

let mut cue_top_nodes = CueLineNode::from_lines(cue_lines);
let cue_top_nodes = CueLineNode::from_lines(cue_lines);

assert_eq!(cue_top_nodes.len(), 16);

Expand All @@ -242,8 +238,6 @@ mod tests {
]
);

// println!("{cue_node:#?}");

assert_eq!(
cue_top_nodes[0],
CueLineNode {
Expand Down
2 changes: 0 additions & 2 deletions src/cue/cue_sheet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
collections::VecDeque,
io::{self},
path::{Path, PathBuf},
time::Duration,
Expand Down Expand Up @@ -29,7 +28,6 @@ pub struct CueFile {

impl CueFile {
fn new(name: String, mut c: Vec<CueSheetItem>) -> Self {
println!("new cue file {name} {c:?}");
let mut tracks = Vec::new();

while let Some(t) = c.pop() {
Expand Down
2 changes: 1 addition & 1 deletion src/cue/cue_sheet_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CueSheetItem {

#[cfg(test)]
mod tests {
use std::{collections::VecDeque, path::Path};
use std::path::Path;

use super::*;
use crate::cue::{cue_line::CueLine, cue_line_node::CueLineNode};
Expand Down
2 changes: 1 addition & 1 deletion src/structs/song.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Song {

pub fn from_cue_sheet(cue_sheet: CueSheet) -> Vec<Self> {
let files = cue_sheet.file();
let cue_file = files.get(0);
let cue_file = files.first();

let Some(cue_file) = cue_file else {
// TODO: nope!
Expand Down

0 comments on commit d5b860b

Please sign in to comment.