Skip to content

Commit 153cf8f

Browse files
committed
add initial guide module
1 parent dd2de06 commit 153cf8f

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ simd = ["std", "memchr/std", "bytecount/runtime-dispatch-simd"]
2626
unicode = ["unicode-width"]
2727
# Enables full context backtraces.
2828
full-backtrace = ["alloc"]
29+
# Enables the guide module.
30+
guide = []
2931

3032
[dependencies]
3133
zc = { version = "0.4", optional = true, default-features = false }

src/guide/bounded.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//! TODO

src/guide/external.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! Using with external types and parsers.
2+
//!
3+
//! TODO

src/guide/faq.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Frequently asked questions (ie. Why can't I do this?)
2+
//!
3+
//! ## Why isn't parsing numbers from string representation supported?
4+
//!
5+
//! Numbers have many different types of representations in string formats and
6+
//! can be parsed in many different ways. While Rust's standard library supports
7+
//! parsing numbers from strings, it doesn't support parsing them directly from
8+
//! bytes. Dangerous seeks to provide a foundation for other parsing libraries
9+
//! leaving the representation and the method of parsing as a downstream
10+
//! concern.
11+
//!
12+
//! Dangerous does implement support via [`error::External`] for the errors
13+
//! returned by the standard library's `from_str_radix` functions. See
14+
//! [`guide::external`] for more information.
15+
//!
16+
//! [`guide::external`]: crate::guide::external
17+
//! [`error::External`]: crate::error::External

src/guide/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Usage guide.
2+
//!
3+
//! # Basic usage
4+
//!
5+
//! ```
6+
//! use dangerous::{Input, Invalid};
7+
//!
8+
//! let input = dangerous::input(b"hello");
9+
//! let result: Result<_, Invalid> = input.read_partial(|r| {
10+
//! r.read()
11+
//! });
12+
//!
13+
//! assert_eq!(result, Ok((b'h', dangerous::input(b"ello"))));
14+
//! ```
15+
//! # Feature flags
16+
//!
17+
//! - `std` (**default feature**): Enables `std::error::Error` support and `alloc`.
18+
//! - `alloc` (**default feature**): Enables allocations.
19+
//! - `simd` (**default feature**): Enables all supported SIMD optimisations.
20+
//! - `unicode` (**default feature**): Enables improved unicode printing support.
21+
//! - `full-backtrace` (**default feature**): Enables collection of all contexts for `Expected`.
22+
//!
23+
//! **Third-party crate support (opt-in)**
24+
//!
25+
//! - `zc`: Enables `zc` crate support.
26+
//! - `nom`: Enables `nom` crate error support.
27+
//! - `regex`: Enables `regex` pattern support.
28+
29+
pub mod bounded;
30+
pub mod external;
31+
pub mod faq;
32+
pub mod streaming;

src/guide/streaming.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//! TODO

src/lib.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
//! Safely and explicitly parse untrusted aka `dangerous` data.
22
//!
3-
//! # Basic usage
4-
//!
5-
//! ```
6-
//! use dangerous::{Input, Invalid};
7-
//!
8-
//! let input = dangerous::input(b"hello");
9-
//! let result: Result<_, Invalid> = input.read_partial(|r| {
10-
//! r.read()
11-
//! });
12-
//!
13-
//! assert_eq!(result, Ok((b'h', dangerous::input(b"ello"))));
14-
//! ```
15-
//!
16-
//! # Feature flags
17-
//!
18-
//! | Feature | Default | Description
19-
//! | ---------------- | ----------- | -------------------------------------------------- |
20-
//! | `std` | **Enabled** | Enables `std::error::Error` support and `alloc` |
21-
//! | `alloc` | **Enabled** | Enables allocations. |
22-
//! | `simd` | **Enabled** | Enables all supported SIMD optimisations. |
23-
//! | `unicode` | **Enabled** | Enables improved unicode printing support. |
24-
//! | `full-backtrace` | **Enabled** | Enables collection of all contexts for `Expected`. |
25-
//! | `zc` | _Disabled_ | Enables `zc` crate support. |
26-
//! | `nom` | _Disabled_ | Enables `nom` crate error support. |
27-
//! | `regex` | _Disabled_ | Enables `regex` pattern support. |
3+
//! See the [`guide`] module to see how to get started.
284
295
///////////////////////////////////////////////////////////////////////////////
306
// Library quirks & hacks
@@ -72,6 +48,8 @@ mod util;
7248
pub mod display;
7349
pub mod error;
7450
pub mod input;
51+
#[cfg(feature = "guide")]
52+
pub mod guide;
7553

7654
pub use self::error::{Error, Expected, Fatal, Invalid, ToRetryRequirement};
7755
pub use self::input::{Bound, ByteArray, Bytes, Input, MaybeString, Span, String};

0 commit comments

Comments
 (0)