Skip to content
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

Tracking Issue for fs_native_path #108979

Open
3 tasks
ChrisDenton opened this issue Mar 10, 2023 · 0 comments
Open
3 tasks

Tracking Issue for fs_native_path #108979

ChrisDenton opened this issue Mar 10, 2023 · 0 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ChrisDenton
Copy link
Member

ChrisDenton commented Mar 10, 2023

Feature gate: #![feature(fs_native_path)]

This is a tracking issue for a new NativePath type that allows users to pass paths more directly to system APIs. This will enable third party crates to implement and experiment with their own path types without having to go through std::path::Path encoding.

Public API

// std::path
pub struct NativePath(_)
pub trait AsPath: Sealed { }

impl<P: AsRef<Path>> AsPath for P { }
impl AsPath for &NativePath { }

// std::os::unix::ffi
pub trait NativePathExt: Sealed {
    fn from_cstr(cstr: &CStr) -> &NativePath;
    fn into_cstr(&self) -> &CStr;
}

// std::os::windows::ffi
// This currently uses a bare `u16` slice but in the future this could perhaps be a `WStr`.
pub trait NativePathExt: Sealed {
    fn from_wide(wide: &[u16]) -> &NativePath;
    unsafe fn from_wide_unchecked(wide: &[u16]) -> &NativePath;
    fn into_wide(&self) -> &[u16];
}

// This also changed the public signature of fs functions.
// Before:
pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<()>
// After:
pub fn create_dir<P: AsPath>(path: P) -> Result<()>

Steps / History

Unresolved Questions

  • The possibility of a Windows equivalent for CStr.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@ChrisDenton ChrisDenton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant