Skip to content

Commit a2cbc32

Browse files
committed
Added clearer use case to README.md example.
1 parent 5b3a109 commit a2cbc32

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ fn main() -> Result<(), DocError> {
4747

4848
fs::write(
4949
&example,
50-
r#"/* Table storing user accounts */
50+
r#"-- Table storing user accounts
51+
-- Contains all user values
52+
/* Rows generated at registration */
5153
CREATE TABLE users (
5254
/* Primary key for each user */
5355
id INTEGER PRIMARY KEY,
@@ -59,7 +61,13 @@ CREATE TABLE users (
5961
)?;
6062

6163
// Extract documentation from a single file
62-
let docs = SqlDoc::from_path(&example).build()?;
64+
let docs = SqlDoc::from_path(&example)
65+
// Capture all valid comment lines preceding the statements directly
66+
.collect_all_leading()
67+
// Replace `\n` with a `str`
68+
.flatten_multiline_with(". ")
69+
// Finally build the `SqlDoc`
70+
.build()?;
6371
// Or extract recursively from a directory
6472
// let docs = SqlDoc::from_dir(&base).build()?;
6573

@@ -69,7 +77,7 @@ CREATE TABLE users (
6977
// Table name
7078
assert_eq!(users.name(), "users");
7179
// Optional table-level documentation
72-
assert_eq!(users.doc(), Some("Table storing user accounts"));
80+
assert_eq!(users.doc(), Some("Table storing user accounts. Contains all user values. Rows generated at registration"));
7381
// Path to the source file
7482
assert_eq!(users.path(), Some(example.as_ref()));
7583

src/sql_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a> SqlDocBuilder<'a> {
226226
self
227227
}
228228

229-
/// Collects all single line comments at most one multiline comment
229+
/// Collects all single line comments and at most one multiline comment
230230
#[must_use]
231231
pub const fn collect_all_single_one_multi(mut self) -> Self {
232232
self.leading_type = LeadingCommentCapture::AllSingleOneMulti;

0 commit comments

Comments
 (0)