Struct MediaDirs
pub struct MediaDirs { pub(crate) desktop: Option<PathBuf>, pub(crate) documents: Option<PathBuf>, pub(crate) downloads: Option<PathBuf>, pub(crate) music: Option<PathBuf>, pub(crate) pictures: Option<PathBuf>, pub(crate) videos: Option<PathBuf>, pub(crate) extra: ExtraMediaDirs }
Common user directory paths used for user-specific media files.
It is not required that the media directories are accessible by the current user, nor that there is a directory at that path. A robust application should handle the case where media directories are incorrectly configured.
Even when configured correctly, multiple paths may point to the same location. You should not assume that a file written relative to one directory will not conflict with the same relative path in a different media directory.
Platform-specific behavior
As the filesystem conventions for discovering directories varies between
operating systems, constructors for MediaDirs that use the host platform's
conventions are provided as extension traits under the std::os module.
Fields
desktop: Option<PathBuf>documents: Option<PathBuf>downloads: Option<PathBuf>music: Option<PathBuf>pictures: Option<PathBuf>videos: Option<PathBuf>extra: ExtraMediaDirs
Implementations
impl MediaDirs
fn set_desktop(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::desktop].
Panics
Panics if the provided path is not absolute.
fn set_documents(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::documents].
Panics
Panics if the provided path is not absolute.
fn set_downloads(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::downloads].
Panics
Panics if the provided path is not absolute.
fn set_music(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::music].
Panics
Panics if the provided path is not absolute.
fn set_pictures(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::pictures].
Panics
Panics if the provided path is not absolute.
fn set_videos(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::videos].
Panics
Panics if the provided path is not absolute.
impl MediaDirs
fn empty() -> SelfCreate a known user directory set with no known directories.
This is useful with the builder
set_*methods to create aMediaDirswith exactly the directories you want, without any other defaults.fn desktop(&self) -> Option<&Path>The OS-recognized user "Desktop" directory, often the
Desktopfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir DESKTOP($HOME/Desktop)Darwin (macOS) NSDesktopDirectory($HOME/Desktop)Windows {FOLDERID_Desktop}(%USERPROFILE%\Desktop)Other paths can be configured via
set_desktop.fn documents(&self) -> Option<&Path>The OS-recognized user "Documents" directory, often the
Documentsfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir DOCUMENTS($HOME/Documents)Darwin (macOS) NSDocumentDirectory($HOME/Documents)Windows {FOLDERID_Documents}(%USERPROFILE%\Documents)Other paths can be configured via
set_documents.fn downloads(&self) -> Option<&Path>The OS-recognized user "Downloads" directory, often the
Downloadsfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir DOWNLOAD($HOME/Downloads)Darwin (macOS) NSDownloadsDirectory($HOME/Downloads)Windows {FOLDERID_Downloads}(%USERPROFILE%\Downloads)Other paths can be configured via
set_downloads.fn music(&self) -> Option<&Path>The OS-recognized user "Music" directory, often the
Musicfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir MUSIC($HOME/Music)Darwin (macOS) NSMusicDirectory($HOME/Music)Windows {FOLDERID_Music}(%USERPROFILE%\Music)Other paths can be configured via
set_music.fn pictures(&self) -> Option<&Path>The OS-recognized user "Pictures" directory, often the
Picturesfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir PICTURES($HOME/Pictures)Darwin (macOS) NSPicturesDirectory($HOME/Pictures)Windows {FOLDERID_Pictures}(%USERPROFILE%\Pictures)Other paths can be configured via
set_pictures.fn videos(&self) -> Option<&Path>The OS-recognized user "Videos" directory, often the
Videosfolder in the user's home directory.As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Platform-specific behavior
When constructed using platform-specific conventions, the value is:
OS Path XDG (Linux) xdg-user-dir VIDEOS($HOME/Videos)Darwin (macOS) NSMoviesDirectory($HOME/Movies)Windows {FOLDERID_Videos}(%USERPROFILE%\Videos)Other paths can be configured via
set_videos.
Trait Implementations
impl Clone for MediaDirs
fn clone(&self) -> Self
impl Debug for MediaDirs
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl MediaDirsExt for MediaDirs
fn xdg() -> Result<Self>fn templates(&self) -> Option<&Path>fn set_templates(&mut self, path: PathBuf) -> &mut Self
Auto Trait Implementations
impl Freeze for MediaDirs
impl RefUnwindSafe for MediaDirs
impl Send for MediaDirs
impl Sync for MediaDirs
impl Unpin for MediaDirs
impl UnsafeUnpin for MediaDirs
impl UnwindSafe for MediaDirs
Blanket Implementations
impl<T> Any for MediaDirs
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for MediaDirs
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for MediaDirs
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for MediaDirs
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for MediaDirs
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for MediaDirs
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for MediaDirs
impl<T> ToOwned for MediaDirs
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for MediaDirs
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for MediaDirs
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for MediaDirs
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>