diff options
author | 2019-11-24 11:55:46 +0100 | |
---|---|---|
committer | 2019-11-24 11:55:46 +0100 | |
commit | 21ec79296e795fa884c10b132ff2957f915f2c02 (patch) | |
tree | 511e710b1dad0d162b7c18a42d8b7932b4cf50c8 /examples/todos.rs | |
parent | 149fd2aa1fa86858c7c1dcec8fd844caa78cec94 (diff) | |
download | iced-21ec79296e795fa884c10b132ff2957f915f2c02.tar.gz iced-21ec79296e795fa884c10b132ff2957f915f2c02.tar.bz2 iced-21ec79296e795fa884c10b132ff2957f915f2c02.zip |
Avoid unnecessary panic in `todos`
Diffstat (limited to 'examples/todos.rs')
-rw-r--r-- | examples/todos.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/todos.rs b/examples/todos.rs index a73c45ce..77013dcc 100644 --- a/examples/todos.rs +++ b/examples/todos.rs @@ -508,8 +508,7 @@ impl SavedState { { project_dirs.data_dir().into() } else { - std::env::current_dir() - .expect("The current directory is not accessible") + std::env::current_dir().unwrap_or(std::path::PathBuf::new()) }; path.push("todos.json"); @@ -538,9 +537,11 @@ impl SavedState { .map_err(|_| SaveError::FormatError)?; let path = Self::path(); - let dir = path.parent().ok_or(SaveError::DirectoryError)?; - std::fs::create_dir_all(dir).map_err(|_| SaveError::DirectoryError)?; + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir) + .map_err(|_| SaveError::DirectoryError)?; + } let mut file = std::fs::File::create(path).map_err(|_| SaveError::FileError)?; |