# Any chance PathBuf could be renamed?

**URL:** <https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673>\
**Category:** bikeshed (deprecated)\
**Created:** [March 3, 2015, 12:20pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673 "2015-03-03T12:20:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkoz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gkoz/32/830_2.png) [@gkoz](https://internals.rust-lang.org/u/gkoz)\
**Post date:** [March 3, 2015, 12:20pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/1 "2015-03-03T12:20:57Z")

</div>

This names seems foreign in Rust. It has no relation to `BufReader` and the company; none of the other owned types that I know of are suffixed with `Buf`. It’s likely to confuse newcomers.

One alternative is to rename `PathBuf` -\> `Path` and `Path` -\> `PathSlice` while either keeping `AsPath` or making it `AsPathSlice`. This relies on the users knowing what a slice is opposed to a `Buf`.

Another possibility is `PathStr` and `PathString`.

~~This got me thinking… Is `PathBuf` sufficiently different from `OsString` to be a separate type? What if there just wasn’t a `PathBuf`? Or would this not play well enough with the `Deref` convention?~~ Nah, that’s silly…

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [March 4, 2015, 10:20am UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/2 "2015-03-04T10:20:12Z")

</div>

`&PathSlice` does not read so nice for me.

---

<div class="post-metadata">

**Author:** ![dan\_t](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan\_t](https://internals.rust-lang.org/u/dan_t)\
**Post date:** [March 4, 2015, 11:47am UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/3 "2015-03-04T11:47:54Z")

</div>

I think the first question is: which of the two should be the nicer readable type?

I consider it somehow wrong, that now the type for holding paths in data structures and returning them by value is now ‘PathBuf’, instead of previously ‘Path’.

So all data structures and also somehow all APIs will have to pay this price.

I don’t see a lot of APIs having to use ‘PathSlice’, because for arguments ‘AsPath’ can be used, and ‘PathSlice’ will most likely be used inside of functions, so the “uglier” name IMHO should be used where it’s more hidden from the API user.

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [March 4, 2015, 12:02pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/4 "2015-03-04T12:02:19Z")

</div>

I consider the current `Path` to be the type that is more important as normally I try to avoid allocations, and `PathBuf` goes right against that principle, needing one allocation per instance. I’d argue that most of the time you’ll be passing the current `&Path` around.

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gkoz/32/830_2.png) [@gkoz](https://internals.rust-lang.org/u/gkoz)\
**Post date:** [March 4, 2015, 12:05pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/5 "2015-03-04T12:05:32Z")

</div>

[quote=“tbu, post:4, topic:1673”] I’d argue that most of the time you’ll be passing the current &Path around. [/quote]Wouldn’t many of those cases actually use `&P where P: AsPath`?

---

<div class="post-metadata">

**Author:** ![tbu](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@tbu](https://internals.rust-lang.org/u/tbu)\
**Post date:** [March 4, 2015, 12:08pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/6 "2015-03-04T12:08:08Z")

</div>

I think that’s just a way for the standard library to overload some file-related functions such as `open` so you can call them with strings as well. The `&P where P: AsPath` needs generics for every function that takes a path.

---

<div class="post-metadata">

**Author:** ![gkoz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/gkoz/32/830_2.png) [@gkoz](https://internals.rust-lang.org/u/gkoz)\
**Post date:** [March 4, 2015, 12:19pm UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/7 "2015-03-04T12:19:45Z")

</div>

I’d expect a lot of public APIs, not just `libstd`, might benefit from substituting `&P: AsPath` for `&Path`. It’s not only strings, but `OsString` as well.

Question is, does less typing (`&Path` vs `&PathSlice`) trump naming consistency (a confusing `PathBuf` vs `Path`)?

Leaving `AsPath` unchanged when `Path` becomes `PathSlice` would be an inconsistency too though…

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:24am UTC](https://internals.rust-lang.org/t/any-chance-pathbuf-could-be-renamed/1673/8 "2019-03-25T08:24:00Z")

</div>

Closed on March 25, 2019, 8:24am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
