pub struct LocalDirs { /* private fields */ }
Expand description
Local directories are meant mostly for debug purposes while developing an application. By
default it provides all available directories under a .local
folder in the current working
directory.
An alternative base directory can be provided with the LocalDirs::new_at
function.
The folders are defined as follows, with <base>
being either .local
or a user defined
directory:
Type | Location |
---|---|
Cache | <base> /cache |
Config | <base> /config |
Data | <base> /data |
Implementations§
source§impl LocalDirs
impl LocalDirs
sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Create a default instance, using the $PWD/.local
directory as a base.
Examples
use std::env;
use unidirs::{Directories, LocalDirs};
let dirs = LocalDirs::new().unwrap();
assert_eq!(env::current_dir().unwrap().join(".local/data"), dirs.data_dir());
sourcepub fn new_at(base: impl AsRef<Utf8Path>) -> Self
pub fn new_at(base: impl AsRef<Utf8Path>) -> Self
Create an instance at the given base directory.
Examples
use tempfile::TempDir;
use unidirs::{Directories, LocalDirs, Utf8Path};
let temp = TempDir::new().unwrap();
let dirs = LocalDirs::new_at(Utf8Path::from_path(temp.path()).unwrap());
assert_eq!(temp.path().join("data"), dirs.data_dir());
Trait Implementations§
source§impl Directories for LocalDirs
impl Directories for LocalDirs
source§fn cache_dir(&self) -> &Utf8Path
fn cache_dir(&self) -> &Utf8Path
The cache directory is a location where an application can save any temporary data. The
contents can potentially be deleted by the system at any time. Therefore, the application
must be able to work without these files or be able to re-create them.
source§fn config_dir(&self) -> &Utf8Path
fn config_dir(&self) -> &Utf8Path
The config directory is where an application’s settings are stored. These are usually
created by the user and loaded once at startup of the application.
source§impl Ord for LocalDirs
impl Ord for LocalDirs
source§impl PartialEq<LocalDirs> for LocalDirs
impl PartialEq<LocalDirs> for LocalDirs
source§impl PartialOrd<LocalDirs> for LocalDirs
impl PartialOrd<LocalDirs> for LocalDirs
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more