-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide UnixPath and WindowsPath (ditto PathBuf) on all platforms #66621
Comments
How would they interact with |
@retep998 Interesting question! The non-native path types wouldn't necessarily be compatible with the native OS string types, which would make it difficult to reuse the code between them. Doing this thoroughly might require providing non-native (Also, all of these shouldn't take up any space in programs that don't use them.) |
There's some precedent here with python's stdlib as well. Python's pathlib implementation allows creation of path objects which only exist ephemerally: Pure Paths, and sub-classed paths which can perform real filesystem operations: Concrete Paths. That said, the biggest difference between the python pathlib and the proposed suggestion is compile-time safety. Python can just throw exceptions on mismatched OS requests and tell the user to fix it, but in rust, we should be able to have compiler-ensured success on most operations. We should even be able to avoid As far as actual implementation goes, Based on the above statement, I personally think that this justifies an RFC, or perhaps a small third-party crate proving the concept. If accepted, it would make sense to keep this in A potential contributor could definitely make a Proof-of-Concept crate at any time, RFC/this issue aside. |
Also, this is being discussed more in the cli-working group repo, although there's a lot of other discussion going on at the same time. https://github.com/rust-lang-nursery/cli-wg/issues/10 |
This would definitely be nice. In Node.js, for example, we provide |
@joshtriplett I just published typed-path to provide a 3rd-party option to do this to some degree. Needed this for a server of mine that accepts user paths and parses them agnostic of the compiled platform. |
…t#328) [Currently](swc-project#327), when `@swc/plugin-emotion` is used on Windows, it produces invalid CSS class names. Apparently this is an [unsolved issue for Rust](rust-lang/rust#66621). In this PR I've updated the calculation of the `[filename]` `labelFormat` such that it handles both the Windows path, which includes the full path to the file, including backslashes, and the Unix path (which was working fine to begin with). I have set up a [minimal repo](https://github.com/iryan2/cra-swc-emotion) for reproducing the issue and verifying the fix. The issue can be reproduced on [the `main` branch](https://github.com/iryan2/cra-swc-emotion), and the fix can be verified on [the `fix` branch](https://github.com/iryan2/cra-swc-emotion/tree/fix). The `fix` branch replaces the compiled `swc_plugin_emotion.wasm` from `@swc/plugin-emotion` npm package with one I built myself via [my fork of this repo](https://github.com/iryan2/swc-plugins/tree/iryan2/fix-emotion-plugin-on-windows). ## Before <img width="612" alt="Screenshot 2024-07-03 at 4 22 41 PM" src="https://github.com/swc-project/plugins/assets/5858312/04a8d2d0-e82f-44b3-90e9-afdcea9ae832"> ## After <img width="626" alt="Screenshot 2024-07-04 at 7 07 42 AM" src="https://github.com/swc-project/plugins/assets/5858312/7bf53d34-fecb-47bd-a71e-eabf35eed22f"> --- Fixes swc-project#327
It would be awesome if there were a way to globally specify which one to use with |
Some applications need to manipulate Windows or UNIX paths on different platforms, for a variety of reasons: constructing portable file formats, parsing files from other platforms, handling archive formats, working with certain network protocols, and so on.
We already have the code in the standard library to manipulate both Windows paths and UNIX paths.
I would propose that we either always support both (as
UnixPath
/UnixPathBuf
andWindowsPath
/WindowsPathBuf
) and alias one of those toPath
/PathBuf
, or that we at least extract that code and upload it verbatim as a standard crate in the ecosystem that specifically documents itself as containing the exact code from the corresponding version of the Rust standard library.I personally think this seems useful enough to include in std, but either solution would potentially work.
cc @sunshowers who mentioned needing this.
The text was updated successfully, but these errors were encountered: