DEV Community

Discussion on: Rust working with paths

 
adam_cyclones profile image
Adam Crockett 🌀

also, interesting that this is part of the fs module. As I said before, I am used to node where this would be part of the path module.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀 • Edited

Also one last thing, what the heck is Ok(()), I keep seeing this in the docs.

Thread Thread
 
deciduously profile image
Ben Lovy • Edited

I hadn't seen any issues with it in my own usage, but there's also path_abs, an external crate which solves this problem. So, the existence of the crate says that there probably is something I don't know about! Good luck.

Thread Thread
 
deciduously profile image
Ben Lovy • Edited

That's an artifact of how rust generally handles errors - all functions return a Result<T, E>. The variants of this type are Ok(T) or Err(E). Functions that don't return a value end up with an Ok(()), signalling success and returning unit. You can only use ? in a fn that returns a Result

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

So it looks like the airquotes problem with canonicalize is that it looks at the real FS. In a cli tool where foo/ is not a dir this would panic (that to me is a real strength!) This is substantially better than node path where it's just a string. Just need catch the error. IL share working code soon.