pub struct File {
pub name: String,
pub path: PathBuf,
pub is_dir: bool,
pub is_hidden: bool,
pub file_type: Option<FileType>,
}Expand description
A file or directory in the file explorer.
Fields§
§name: StringThe name of the file or directory.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can get the name of the selected file like this:
use ratatui_explorer::FileExplorer;
let file_explorer = FileExplorer::new().unwrap();
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.name, "passport.png");path: PathBufReturns the path of the file or directory.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can get the path of the selected file like this:
use ratatui_explorer::FileExplorer;
let file_explorer = FileExplorer::new().unwrap();
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.path.display().to_string(), "/Documents/passport.png");is_dir: boolIs true is the file is a directory.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can know if the selected file is a directory like this:
use ratatui_explorer::FileExplorer;
let file_explorer = FileExplorer::new().unwrap();
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.is_dir, false);
/* user select `Documents` */
let file = file_explorer.current();
assert_eq!(file.is_dir, true);Is true if the file or directory is hidden.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can know if the selected file or directory is hidden like this:
use ratatui_explorer::FileExplorer;
let mut file_explorer = FileExplorer::new().unwrap();
file_explorer.set_show_hidden(true);
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.is_hidden, false);
/* user select `.git` */
let file = file_explorer.current();
assert_eq!(file.is_hidden, true);file_type: Option<FileType>The FileType of the file, when available.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can know if the selected file is a directory like this:
use ratatui_explorer::FileExplorer;
let file_explorer = FileExplorer::new().unwrap();
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.file_type.unwrap().is_dir(), false);
/* user select `Documents` */
let file = file_explorer.current();
assert_eq!(file.file_type.unwrap().is_dir(), true);Implementations§
Source§impl File
impl File
Sourcepub fn is_file(&self) -> bool
pub fn is_file(&self) -> bool
Returns true is the file is a regular file.
§Examples
Suppose you have this tree file, with passport.png selected inside file_explorer:
/
├── .git
└── Documents
├── passport.png <- selected
└── resume.pdfYou can know if the selected file is a directory like this:
use ratatui_explorer::FileExplorer;
let file_explorer = FileExplorer::new().unwrap();
/* user select `password.png` */
let file = file_explorer.current();
assert_eq!(file.is_file(), true);
/* user select `Documents` */
let file = file_explorer.current();
assert_eq!(file.is_file(), false);pub fn name(&self) -> &str
name field is public and should be acceded with .name
pub const fn path(&self) -> &PathBuf
path field is public and should be acceded with .path
pub const fn is_dir(&self) -> bool
is_dir field is public and should be acceded with .is_dir
is_hidden field is public and should be acceded with .is_hidden
pub const fn file_type(&self) -> Option<FileType>
file_type field is public and should be acceded with .file_type
Trait Implementations§
impl Eq for File
impl StructuralPartialEq for File
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more