Skip to content

Commit 1de251d

Browse files
Add "Quick Start" section to the docs
1 parent 618d9a5 commit 1de251d

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/lib.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,35 @@
99
//! built. This crate also offers a bit more flexibility compared to `syn`
1010
//! (only regarding literals, of course).
1111
//!
12-
//! ---
12+
//!
13+
//! # Quick start
14+
//!
15+
//! | **`StringLit::try_from(tt)?.value()`** |
16+
//! | - |
17+
//!
18+
//! ... where `tt` is a `proc_macro::TokenTree` and where [`StringLit`] can be
19+
//! replaced with [`Literal`] or other types of literals (e.g. [`FloatLit`]).
20+
//! Calling `value()` returns the value that is represented by the literal.
21+
//!
22+
//! **Mini Example**
23+
//!
24+
//! ```ignore
25+
//! use proc_macro::TokenStream;
26+
//!
27+
//! #[proc_macro]
28+
//! pub fn foo(input: TokenStream) -> TokenStream {
29+
//! let first_token = input.into_iter().next().unwrap(); // Do proper error handling!
30+
//! let string_value = match litrs::StringLit::try_from(first_token) {
31+
//! Ok(string_lit) => string_lit.value(),
32+
//! Err(e) => return e.to_compile_error(),
33+
//! };
34+
//!
35+
//! // `string_value` is the string value with all escapes resolved.
36+
//! todo!()
37+
//! }
38+
//! ```
39+
//!
40+
//! # Overview
1341
//!
1442
//! The main types of this library are [`Literal`], representing any kind of
1543
//! literal, and `*Lit`, like [`StringLit`] or [`FloatLit`], representing a
@@ -41,8 +69,8 @@
4169
//!
4270
//! **Note**: `true` and `false` are `Ident`s when passed to your proc macro.
4371
//! The `TryFrom<TokenTree>` impls check for those two special idents and
44-
//! return a `BoolLit` appropriately. For that reason, there is also no
45-
//! `TryFrom<proc_macro::Literal>` impl for `BoolLit`. The `proc_macro::Literal`
72+
//! return a [`BoolLit`] appropriately. For that reason, there is also no
73+
//! `TryFrom<proc_macro::Literal>` impl for [`BoolLit`]. The `proc_macro::Literal`
4674
//! simply cannot represent bool literals.
4775
//!
4876
//!

0 commit comments

Comments
 (0)