D7864: rust-utils: add Rust implementation of Python's "os.path.splitdrive"

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Wed Jan 15 14:42:07 EST 2020


Alphare added inline comments.

INLINE COMMENTS

> kevincox wrote in files.rs:109
> I think this can be simplified. See https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=78136ead96596afe6305e7542a881ca4. I had to use &[u8] to avoid having to copy all of the HgPath stuff into the playground, but the code should be easy to integrate.
> 
> Notable changes:
> 
> - Avoid creating `norm_bytes` vector (and allocation) by creating an is_sep function.
>   - Note, we can probably use std::path::is_separator <https://doc.rust-lang.org/std/path/fn.is_separator.html>
> - Return references to the input since we guarantee that the output will be parts of the input. The caller can always clone.
> - Use slice::split_at to make it obvious that we are returning the entire path just split.
> - Use pattern matching rather than unwrapping.
> - Use fall-through returns to make it obvious we handle every path.

Indeed, this is much better. While trying to adapt this code to fit with `HgPath`, I find myself needing to translate to and from bytes whenever indexing or when using `split_at`. Should we give a `HgPath` a `split_at` method or also all the `Index<>` ones? I remember that we decided against that earlier.

> kevincox wrote in files.rs:230
> We should add an example of a UNC and Drive path here to ensure that they don't get split.

Good idea

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7864/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7864

To: Alphare, #hg-reviewers, kevincox
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list