add file_prefix method to std::path by mbhall88 · Pull Request #85166 · rust-lang/rust (original) (raw)

This is an initial implementation of std::path::Path::file_prefix. It is effectively a "left" variant of the existing file_stem method. An illustration of the difference is

use std::path::Path;

let path = Path::new("foo.tar.gz"); assert_eq!(path.file_stem(), Some("foo.tar")); assert_eq!(path.file_prefix(), Some("foo"));

In my own development, I generally find I almost always want the prefix, rather than the stem, so I thought it might be best to suggest it's addition to libstd.

Of course, as this is my first contribution, I expect there is probably more work that needs to be done. Additionally, if the libstd team feel this isn't appropriate then so be it.

There has been some discussion about this on Zulip and a user there suggested I open a PR to see whether someone in the libstd team thinks it is worth pursuing.