Skip to content

Tracking Issue for fs_native_path #108979

Open

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 ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Mar 10, 2023
  2. tbu- commented on Dec 11, 2025

    @tbu-
    Contributor

    This needs a way to ensure that there are no internal null UTF-16 code units on Windows, the currently proposed API doesn't do that, as far as I can tell.

  3. ChrisDenton commented on Dec 11, 2025

    @ChrisDenton
    MemberAuthor

    That's why there's both a from_wide and a from_wide_unchecked (which is unsafe). The former checks for nulls but the latter doesn't.

  4. tbu- commented on Dec 17, 2025

    @tbu-
    Contributor

    What does from_wide do when there are internal NULs? Panic?

    If that's proposed, I'd think that returning a Result<…> would be more appropriate, like with CStr::from_bytes_with_nul.

  5. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  6. bardiharborow commented on Aug 24, 2026

    @bardiharborow
    Contributor

    @rustbot label +A-io +A-filesystem +A-ffi

  7. added
    A-FFIArea: Foreign function interface (FFI)
    A-ioArea: `std::io` (note: `std::fs`, `std::net`, `std::path` are A-filesystem, A-net, A-path)
    on Aug 24, 2026
  8. added
    A-pathArea: `std::path` (note: `std::fs` is A-filesystem)
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-filesystemArea: `std::fs`A-ioArea: `std::io` (note: `std::fs`, `std::net`, `std::path` are A-filesystem, A-net, A-path)A-pathArea: `std::path` (note: `std::fs` is A-filesystem)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libsRelevant to the library 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