Skip to content

Tracking Issue for fs_native_path #108979

Open
@ChrisDenton

Description

@ChrisDenton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions