if I'm making a rust type/module that works with paths, what should its arguments be? Path? PathBuf? AsRef<Path>? Deref<Target=Path>? Borrow<Path>? I am confused
-
Show this thread
-
Replying to @mountain_ghosts
AsRef<Path> if you don't need to own the path T: Deref<Target=Foo> is a pretty rare bound.
1 reply 0 retweets 2 likes -
Replying to @ManishEarth
often I'm just gonna be calling join() on it to make new paths, or navigating up/down the tree, so I only need a &Path for that
1 reply 0 retweets 1 like -
Replying to @mountain_ghosts @ManishEarth
is it rare to explicitly use T: Deref b/c Deref provides implicit conversion from &T to &U, and the called function doesn't need to declare a Deref?
2 replies 0 retweets 1 like -
Replying to @mountain_ghosts @ManishEarth
in which case, why do things take AsRef<Path> rather than just &Path and let Deref do its magic? is it important that AsRef can be implemented multiple times and Deref cannot?
2 replies 0 retweets 1 like -
Replying to @mountain_ghosts
it's mostly laziness, if you don't take AsRef<Path> then you might be forced to use & on the argument i'm hoping we'll eventually just make this a coercion, but opinions are divided (people like costs to be explicit)
1 reply 0 retweets 6 likes
Method syntax would have never landed if proposed today
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.