Skip to content

Commit

Permalink
actual debug impl
Browse files Browse the repository at this point in the history
  • Loading branch information
edwloef committed Jan 4, 2025
1 parent 86e9ade commit eca2ee5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
12 changes: 1 addition & 11 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use iced::{
};
use std::{
cell::{OnceCell, RefCell},
fmt::{Debug, Formatter},
ops::Deref,
path::PathBuf,
rc::Rc,
Expand Down Expand Up @@ -43,7 +42,7 @@ impl<Message> Default for State<Message> {
#[expect(clippy::type_complexity)]
#[derive(Clone)]
pub struct Dir<Message> {
path: PathBuf,
pub path: PathBuf,
name: String,
dirs: OnceCell<Rc<[Dir<Message>]>>,
files: OnceCell<Rc<[File<Message>]>>,
Expand All @@ -53,15 +52,6 @@ pub struct Dir<Message> {
pub show_extensions: bool,
}

impl<Message> Debug for Dir<Message> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Dir")
.field("path", &self.path)
.field("show_hidden", &self.show_hidden)
.finish_non_exhaustive()
}
}

impl<Message> Dir<Message>
where
Message: Clone + 'static,
Expand Down
15 changes: 1 addition & 14 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ use iced::{
event::Status,
Event, Length, Rectangle, Renderer, Size, Theme, Vector,
};
use std::{
cell::RefCell,
fmt::{Debug, Formatter},
path::PathBuf,
rc::Rc,
};
use std::{cell::RefCell, path::PathBuf, rc::Rc};

const FILE: &[u8] = include_bytes!("../assets/system-uicons--document.svg");

Expand All @@ -36,14 +31,6 @@ pub struct File<Message> {
on_double_click: Rc<RefCell<Option<Box<dyn Fn(PathBuf) -> Message>>>>,
}

impl<Message> Debug for File<Message> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("File")
.field("path", &self.path)
.finish_non_exhaustive()
}
}

impl<Message> File<Message> {
#[expect(clippy::type_complexity)]
pub fn new_inner(
Expand Down
17 changes: 15 additions & 2 deletions src/file_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use iced::{
mouse::Cursor,
Element, Event, Length, Rectangle, Renderer, Size, Theme,
};
use std::{path::PathBuf, rc::Rc};
use std::{
fmt::{Debug, Formatter},
path::PathBuf,
rc::Rc,
};

/// A lightweight file tree widget for the [iced](https://github.com/iced-rs/iced/tree/master) toolkit.
///
Expand All @@ -35,9 +39,18 @@ use std::{path::PathBuf, rc::Rc};
/// .into()
/// }
/// ```
#[derive(Debug)]
pub struct FileTree<Message>(Dir<Message>);

impl<Message> Debug for FileTree<Message> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Dir")
.field("path", &self.0.path)
.field("show_hidden", &self.0.show_hidden)
.field("show_extensions", &self.0.show_hidden)
.finish()
}
}

/// Creates a new [`FileTree`] with the root at the given path.
#[must_use]
pub fn file_tree<Message>(path: PathBuf) -> Option<FileTree<Message>>
Expand Down

0 comments on commit eca2ee5

Please sign in to comment.