Skip to content

Commit

Permalink
Clean up README and only integrate README docs when std feature is set
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Nov 4, 2023
1 parent bbc4361 commit 2423bb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "typed-path"
description = "Provides typed variants of Path and PathBuf for Unix and Windows"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
authors = ["Chip Senkbeil <[email protected]>"]
categories = ["development-tools", "filesystem", "os"]
Expand All @@ -11,13 +11,11 @@ repository = "https://github.com/chipsenkbeil/typed-path"
readme = "README.md"
license = "MIT OR Apache-2.0"

[[example]]
name = "windows_utf8"
required-features = ["std"]
[dependencies]

[[example]]
name = "unix"
required-features = ["std"]
[features]
default = ["std"]
std = []

[[example]]
name = "typed"
Expand All @@ -27,6 +25,10 @@ required-features = ["std"]
name = "typed_utf8"
required-features = ["std"]

[[example]]
name = "unix"
required-features = ["std"]

[[example]]
name = "unix_utf8"
required-features = ["std"]
Expand All @@ -35,8 +37,6 @@ required-features = ["std"]
name = "windows"
required-features = ["std"]

[dependencies]

[features]
default = ["std"]
std = []
[[example]]
name = "windows_utf8"
required-features = ["std"]
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,20 @@ form by prepending the current working directory if the path is relative and
then normalizing it (requires `std` feature):

```rust
# fn main() {
# // absolutize is only supported with standard library
# #[cfg(feature = "std")]
# {
use typed_path::{utils, Utf8UnixPath};

// With an absolute path, it is just normalized
// NOTE: This requires `std` feature, otherwise `absolutize` is missing!
let path = Utf8UnixPath::new("/a/b/../c/./d");
assert_eq!(path.absolutize().unwrap(), Utf8UnixPath::new("/a/c/d"));

// With a relative path, it is first joined with the current working directory
// and then normalized
// NOTE: This requires `std` feature, otherwise `utf8_current_dir` and
// `absolutize` are missing!
let cwd = utils::utf8_current_dir().unwrap().with_unix_encoding();
let path = cwd.join(Utf8UnixPath::new("a/b/../c/./d"));
assert_eq!(path.absolutize().unwrap(), cwd.join(Utf8UnixPath::new("a/c/d")));
# }
# }
```

### Current directory
Expand All @@ -217,23 +214,21 @@ feature), and one of those provides an identical experience to
[`std::env::current_dir`](https://doc.rust-lang.org/std/env/fn.current_dir.html):

```rust
# fn main() {
# // utils::current_dir is only supported with standard library
# #[cfg(feature = "std")]
# {
// Retrieves the current directory as a NativePath:
//
// * For Unix family, this would be Path<UnixEncoding>
// * For Windows family, this would be Path<WindowsEncoding>
//
// NOTE: This requires `std` feature, otherwise `current_dir` is missing!
let _cwd = typed_path::utils::current_dir().unwrap();

// Retrieves the current directory as a Utf8NativePath:
//
// * For Unix family, this would be Utf8Path<Utf8UnixEncoding>
// * For Windows family, this would be Utf8Path<Utf8WindowsEncoding>
//
// NOTE: This requires `std` feature, otherwise `utf8_current_dir` is missing!
let _utf8_cwd = typed_path::utils::utf8_current_dir().unwrap();
# }
# }
```

## License
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "std", doc = include_str!("../README.md"))]
#![cfg_attr(not(feature = "std"), no_std)]

#[doc = include_str!("../README.md")]
Expand Down

0 comments on commit 2423bb4

Please sign in to comment.