Personally I’m very hesitant when it comes to overloading operators for anything, but their original purpose. I particularly dislike abusing operator overloading to build mini DSLs, which I’d argue this is a case of.
Furthermore, if we are doing such overloading, I find it hard to argue for having different operators to append data, depending on the type. I can sort of get on board with “Adding/appending a string to another one”, and the operator being + (i.e. addition). However, why is “Adding/appending a path to another one” represented by a different operator / (i.e. division) instead? The answer is obviously that this looks familiar, but from a completely different context than Rust programming.
I’d prefer if we encapsulated such DSLs within macros, e.g.:
// Usage: path_join!(a/b/c)
macro_rules! path_join {
( $first:ident / $( $path:ident )/ * ) => {
{
let mut tmp: PathBuf = $first.into();
$(
tmp = tmp.join($path);
)*
tmp
}
}
}
I fully admit that this only works for the simplest cases though.