Skip to content

Commit

Permalink
Document user_directories.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxcode committed Feb 1, 2024
1 parent 66650e4 commit eb8b341
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/data/user_directories.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fs;
use std::path::{Path, PathBuf};

/// Wrapper above directories::UserDirs.
/// Currently only used to canonicalize the paths.
#[derive(Default, Clone)]
pub struct UserDirectories {
home_dir: Option<PathBuf>,
Expand All @@ -14,6 +16,8 @@ pub struct UserDirectories {
}

impl UserDirectories {
/// Creates a new UserDirectories object.
/// Returns None if no valid home directory path could be retrieved from the operating system.
pub fn new() -> Option<Self> {
if let Some(dirs) = directories::UserDirs::new() {
return Some(Self {
Expand Down Expand Up @@ -59,6 +63,7 @@ impl UserDirectories {
self.video_dir.as_deref()
}

/// Canonicalizes the given paths. Returns None if an error occurred.
fn canonicalize(path: Option<&Path>) -> Option<PathBuf> {
if let Some(path) = path {
return match fs::canonicalize(path) {
Expand Down

0 comments on commit eb8b341

Please sign in to comment.