Rust: the issue of filenames and Python interop

Raphaël Gomès raphael.gomes at octobus.net
Mon Aug 26 16:17:57 UTC 2019


Hi all,

Ever since the start of the OxidationPlan, there has been discussion 
here and there about both the way we handle paths within Rust and how 
the interop with Python plays out in that regard.
As of now, we decided to put off solving the issue and we use bytes, 
since it works fine on Unix-like platforms. This means that Rust code 
does not work on Windows, that we're not leveraging Rust's standard 
library like we should, rendering the Rust code un-idiomatic and harder 
to write.

 From the perspective of our pure-rust "hg-core" library, we should be 
using https://doc.rust-lang.org/std/path/struct.Path.html, 
https://doc.rust-lang.org/std/ffi/struct.OsString.html and their owned 
variants to represent paths and filenames.

I am not 100% sure of what the compatibility layer should do. From what 
I can see, rust-cpython enforces UTF8 when the string is non-ascii 
(https://docs.rs/cpython/0.3.0/src/cpython/objects/string.rs.html#242), 
which we cannot accept as filenames can be something other than UTF8. Is 
using https://doc.rust-lang.org/std/ffi/struct.CStr.html the right 
solution, or am I going in the wrong direction?

I prefer asking this question here beforehand instead of hitting a 
dead-end because I don't have the knowledge some of you do.



More information about the Mercurial-devel mailing list