Skip to content

Commit d3e0948

Browse files
authored
Add examples for platform path (#42)
1 parent 81c9b89 commit d3e0948

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ jobs:
115115
run: cargo run --example typed
116116
- name: typed UTF8 Example
117117
run: cargo run --example typed_utf8
118+
- name: platform Example
119+
run: cargo run --example platform
120+
- name: platform UTF8 Example
121+
run: cargo run --example platform_utf8

examples/platform.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use typed_path::PlatformPath;
2+
3+
fn main() {
4+
// You can create the path like normal, but it is a distinct encoding from Unix/Windows
5+
let path = PlatformPath::new("some/path");
6+
7+
// The path will still behave like normal and even report its underlying encoding
8+
assert_eq!(path.has_unix_encoding(), cfg!(unix));
9+
assert_eq!(path.has_windows_encoding(), cfg!(windows));
10+
11+
// It can still be converted into specific platform paths
12+
let _ = path.with_unix_encoding();
13+
let _ = path.with_windows_encoding();
14+
}

examples/platform_utf8.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use typed_path::Utf8PlatformPath;
2+
3+
fn main() {
4+
// You can create the path like normal, but it is a distinct encoding from Unix/Windows
5+
let path = Utf8PlatformPath::new("some/path");
6+
7+
// The path will still behave like normal and even report its underlying encoding
8+
assert_eq!(path.has_unix_encoding(), cfg!(unix));
9+
assert_eq!(path.has_windows_encoding(), cfg!(windows));
10+
11+
// It can still be converted into specific platform paths
12+
let _ = path.with_unix_encoding();
13+
let _ = path.with_windows_encoding();
14+
}

0 commit comments

Comments
 (0)