4 ms·
Yes, but it's awkward to work with from the caller's side. You'd have to do something like this (hard to pick non-clashy names, too): enum Path { Fr
by kelnos 9y ago
Yes, but it's awkward to work with from the caller's side. You'd have to do something like this (hard to pick non-clashy names, too):
enum Path {
FromString(String),
FromStr(&str),
FromOsStr(OsStr),
// ...
}
fn open(path: Path) ... {
}
And then as the caller you'd have to do things like:
let file = open(Path::FromStr("/foo/bar"));
It's not particularly nice to read, and you also have the overhead of creating and throwing away the enum instance.
- wtetzner 9y agoAn using AsRef means you can define your own types that can be used as paths, whereas an enum would be fixed once it was defined.