Env::current_dir() Vs dirs::desktop_dir()

#1

env::current_dir() and friends return Result<PathBuf> and dirs::desktop_dir() and friends return Option<PathBuf>

Is there some sort of decision criterion that should be applied to choose whether Result or Option is returned?

I can think of returning “meaningful errors” as one. But is there any reason that these two things differ in their return types, or not really?

0 Likes

#2

It’s often just a matter of judgement.

Result is for “there should be a dir, but we couldn’t get it”.

Option is for “there could be a dir, but sometimes there isn’t and that’s expected”.

1 Like