{"id":15387270,"url":"https://github.com/rhysd/path-slash","last_synced_at":"2025-05-16T06:04:47.243Z","repository":{"id":41413218,"uuid":"163569806","full_name":"rhysd/path-slash","owner":"rhysd","description":"Tiny Rust library to convert a file path from/to slash path","archived":false,"fork":false,"pushed_at":"2025-01-06T13:41:40.000Z","size":64,"stargazers_count":60,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-09T23:05:27.144Z","etag":null,"topics":["backslash","path","rust","slash"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/path-slash","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-30T07:26:28.000Z","updated_at":"2025-03-17T07:15:29.000Z","dependencies_parsed_at":"2025-01-20T23:10:46.064Z","dependency_job_id":"3c1510b0-e8f6-4b8c-870c-339613b0306b","html_url":"https://github.com/rhysd/path-slash","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fpath-slash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fpath-slash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fpath-slash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fpath-slash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/path-slash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478186,"owners_count":22077675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backslash","path","rust","slash"],"created_at":"2024-10-01T14:53:08.761Z","updated_at":"2025-05-16T06:04:47.225Z","avatar_url":"https://github.com/rhysd.png","language":"Rust","readme":"Rust library to convert a file path from/to slash path\n======================================================\n[![crates.io][crates-io-badge]][crates-io]\n[![documentation][doc-badge]][doc]\n[![CI][ci-badge]][ci]\n[![codecov-badge][]][codecov]\n\n[`path-slash`][crates-io] is a tiny library to convert a file path (e.g. `foo/bar`, `foo\\bar` or\n`C:\\foo\\bar`) from/to slash path (e.g. `foo/bar`, `C:/foo/bar`).\n\nOn Unix-like OS, path separator is slash `/` by default. One may want to convert a Windows path. But on\nWindows, file path separator `\\` needs to be replaced with slash `/` (and of course `\\`s for escaping\ncharacters should not be replaced).\n\nSupported Rust version is 1.38.0 or later.\n\nThis package was inspired by Go's [`path/filepath.FromSlash`](https://pkg.go.dev/path/filepath#FromSlash)\nand [`path/filepath.ToSlash`](https://pkg.go.dev/path/filepath#ToSlash).\n\n## Usage\n\n`path_slash::PathExt`, `path_slash::PathBufExt` and `path_slash::CowExt` traits are defined. By using them,\n`std::path::Path`, `std::path::PathBuf` and `std::borrow::Cow\u003c'_, Path\u003e` gain some methods and associated functions.\n\n- `PathExt`\n  - `Path::to_slash(\u0026self) -\u003e Option\u003cCow\u003c'_, str\u003e\u003e`\n  - `Path::to_slash_lossy(\u0026self) -\u003e Cow\u003c'_, str\u003e`\n- `PathBufExt`\n  - `PathBuf::from_slash\u003cS: AsRef\u003cstr\u003e\u003e(s: S) -\u003e PathBuf`\n  - `PathBuf::from_slash_lossy\u003cS: AsRef\u003cOsStr\u003e\u003e(s: S) -\u003e PathBuf`\n  - `PathBuf::from_backslash\u003cS: AsRef\u003cstr\u003e\u003e(s: S) -\u003e PathBuf`\n  - `PathBuf::from_backslash_lossy\u003cS: AsRef\u003cOsStr\u003e\u003e(s: S) -\u003e PathBuf`\n  - `PathBuf::to_slash(\u0026self) -\u003e Option\u003cCow\u003c'_, str\u003e\u003e`\n  - `PathBuf::to_slash_lossy(\u0026self) -\u003e Cow\u003c'_, str\u003e`\n- `CowExt`\n  - `Cow::\u003cPath\u003e::from_slash(s: \u0026str) -\u003e Cow\u003c'_, Path\u003e`\n  - `Cow::\u003cPath\u003e::from_slash_lossy(s: \u0026OsStr) -\u003e Cow\u003c'_, Path\u003e`\n  - `Cow::\u003cPath\u003e::from_backslash(s: \u0026str) -\u003e Cow\u003c'_, Path\u003e`\n  - `Cow::\u003cPath\u003e::from_backslash_lossy(s: \u0026OsStr) -\u003e Cow\u003c'_, Path\u003e`\n  - `Cow::\u003cPath\u003e::to_slash(\u0026self) -\u003e Option\u003cCow\u003c'_, str\u003e\u003e`\n  - `Cow::\u003cPath\u003e::to_slash_lossy(\u0026self) -\u003e Cow\u003c'_, str\u003e`\n\n```rust\nfn example_path_ext() {\n    // Trait for extending std::path::Path\n    use path_slash::PathExt as _;\n\n    let p = Path::from_slash(\"foo/bar/piyo.txt\");\n\n    // On Windows\n    assert_eq!(p, Path::new(r\"foo\\bar\\piyo.txt\"));\n\n    // Convert to slash path\n    assert_eq!(p.to_slash().unwrap(), \"foo/bar/piyo.txt\");\n    assert_eq!(p.to_slash_lossy(), \"foo/bar/piyo.txt\");\n}\n\nfn example_pathbuf_ext() {\n    // Trait for extending std::path::PathBuf\n    use path_slash::PathBufExt as _;\n\n    // On Windows\n    let p = PathBuf::from_slash(\"foo/bar/piyo.txt\");\n    assert_eq!(p, PathBuf::from(r\"foo\\bar\\piyo.txt\"));\n\n    // Convert to slash path\n    assert_eq!(p.to_slash().unwrap(), \"foo/bar/piyo.txt\");\n    assert_eq!(p.to_slash_lossy(), \"foo/bar/piyo.txt\");\n}\n\nfn example_cow_ext() {\n    // Trait for extending std::borrow::Cow\u003c'_, Path\u003e\n    use path_slash::CowExt as _;\n\n    let p = Cow::from_slash(\"foo/bar/piyo.txt\");\n    // On Windows\n    assert_eq!(p, Cow::Owned(PathBuf::from(r\"foo\\bar\\piyo.txt\")));\n    // On non-Windows\n    assert_eq!(p, Cow::Borrowed(Path::new(\"foo/bar/piyo.txt\")));\n\n    // Convert to slash path\n    assert_eq!(p.to_slash().unwrap(), \"foo/bar/piyo.txt\");\n    assert_eq!(p.to_slash_lossy(), \"foo/bar/piyo.txt\");\n}\n```\n\nPlease read [documents][doc] for more details.\n\n## Installation\n\nAdd `path-slash` to dependencies:\n\n```toml\n[dependencies]\npath-slash = \"0.x\"\n```\n\n## License\n\n[the MIT License](LICENSE.txt)\n\n[doc-badge]: https://docs.rs/path-slash/badge.svg\n[doc]: https://docs.rs/path-slash\n[crates-io-badge]: https://img.shields.io/crates/v/path-slash.svg\n[crates-io]: https://crates.io/crates/path-slash\n[ci]: https://github.com/rhysd/path-slash/actions/workflows/ci.yaml\n[ci-badge]: https://github.com/rhysd/path-slash/actions/workflows/ci.yaml/badge.svg\n[codecov-badge]: https://codecov.io/gh/rhysd/path-slash/branch/master/graph/badge.svg?token=6f7QWopfz4\n[codecov]: https://codecov.io/gh/rhysd/path-slash\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fpath-slash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Fpath-slash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fpath-slash/lists"}