ratatui_toolkit/widgets/file_system_tree/constructors/
new_entry.rs

1use anyhow::Result;
2use std::path::PathBuf;
3
4use crate::widgets::file_system_tree::FileSystemEntry;
5
6impl FileSystemEntry {
7    pub fn new(path: PathBuf) -> Result<Self> {
8        let name = path
9            .file_name()
10            .and_then(|n| n.to_str())
11            .unwrap_or("")
12            .to_string();
13
14        let is_dir = path.is_dir();
15        let is_hidden = name.starts_with('.');
16
17        Ok(Self {
18            name,
19            path,
20            is_dir,
21            is_hidden,
22        })
23    }
24}