Skip to main content

FilePickerState

Struct FilePickerState 

Source
pub struct FilePickerState {
    pub current_dir: PathBuf,
    pub entries: Vec<FileEntry>,
    pub selected: usize,
    pub selected_file: Option<PathBuf>,
    pub show_hidden: bool,
    pub extensions: Vec<String>,
    pub dirty: bool,
    /* private fields */
}
Expand description

State for a file picker widget.

Tracks the current directory listing, filtering options, and selected file.

Fields§

§current_dir: PathBuf

Current directory being browsed.

§entries: Vec<FileEntry>

Visible entries in the current directory.

§selected: usize

Selected entry index in entries.

§selected_file: Option<PathBuf>

Currently selected file path, if any.

§show_hidden: bool

Whether dotfiles are included in the listing.

§extensions: Vec<String>

Allowed file extensions (lowercase, no leading dot).

§dirty: bool

Whether the directory listing needs refresh.

Implementations§

Source§

impl FilePickerState

Source

pub fn new(dir: impl Into<PathBuf>) -> Self

Create a file picker rooted at dir.

Source

pub fn show_hidden(self, show: bool) -> Self

Configure whether hidden files should be shown.

Source

pub fn extensions(self, exts: &[&str]) -> Self

Restrict visible files to the provided extensions.

Source

pub fn scan_status(&self) -> FilePickerScanStatus

Return the freshness of the current directory listing.

Source

pub fn scan_errors(&self) -> &[FilePickerScanError]

Return every failure captured by the most recent scan.

A root read_dir failure produces one error and retains the previous listing. Per-entry and metadata failures produce a best-effort listing.

Source

pub fn last_error(&self) -> Option<&FilePickerScanError>

Return the most recent failure from the latest scan.

Source

pub fn retry(&mut self)

Request another scan after a transient failure.

Source

pub fn selected_file(&self) -> Option<&PathBuf>

Return the currently selected file path, if any.

Disambiguates from the selected: usize field, which is the entry index into entries. This method returns the resolved file path that the user picked via Enter — None until a file (not a directory) is selected.

§Example
let mut state = FilePickerState::new(".");
if ui.file_picker(&mut state).changed {
    if let Some(path) = state.selected_file() {
        println!("picked: {}", path.display());
    }
}
Source

pub fn selected(&self) -> Option<&PathBuf>

👎Deprecated since 0.20.0:

use selected_file() — disambiguates from the selected: usize field index

Return the currently selected file path.

Deprecated alias for selected_file. The shorter name conflicts visually with the selected: usize field — a getter returning a path alongside a public field returning an index made call sites ambiguous. Migrate to selected_file() for new code; this stub stays callable until v1.0.

Source

pub fn refresh(&mut self)

Re-scan the current directory, retaining failures in scan_errors.

This compatibility wrapper ignores the returned error. Use try_refresh when the caller needs immediate fallible control flow.

Source

pub fn try_refresh(&mut self) -> Result<(), FilePickerScanError>

Re-scan the current directory and rebuild entries.

Root directory failures retain the previous listing. Entry-read and file-type failures skip only the affected entry. Metadata failures keep the file with FileEntry::size set to None. Any partial failure is returned and remains inspectable through scan_errors.

Trait Implementations§

Source§

impl Clone for FilePickerState

Source§

fn clone(&self) -> FilePickerState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FilePickerState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FilePickerState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.