Skip to content

Commit

Permalink
Add examples for platform path (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil authored Dec 1, 2024
1 parent 81c9b89 commit d3e0948
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ jobs:
run: cargo run --example typed
- name: typed UTF8 Example
run: cargo run --example typed_utf8
- name: platform Example
run: cargo run --example platform
- name: platform UTF8 Example
run: cargo run --example platform_utf8
14 changes: 14 additions & 0 deletions examples/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use typed_path::PlatformPath;

fn main() {
// You can create the path like normal, but it is a distinct encoding from Unix/Windows
let path = PlatformPath::new("some/path");

// The path will still behave like normal and even report its underlying encoding
assert_eq!(path.has_unix_encoding(), cfg!(unix));
assert_eq!(path.has_windows_encoding(), cfg!(windows));

// It can still be converted into specific platform paths
let _ = path.with_unix_encoding();
let _ = path.with_windows_encoding();
}
14 changes: 14 additions & 0 deletions examples/platform_utf8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use typed_path::Utf8PlatformPath;

fn main() {
// You can create the path like normal, but it is a distinct encoding from Unix/Windows
let path = Utf8PlatformPath::new("some/path");

// The path will still behave like normal and even report its underlying encoding
assert_eq!(path.has_unix_encoding(), cfg!(unix));
assert_eq!(path.has_windows_encoding(), cfg!(windows));

// It can still be converted into specific platform paths
let _ = path.with_unix_encoding();
let _ = path.with_windows_encoding();
}

0 comments on commit d3e0948

Please sign in to comment.