Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
quote-doctest - Create doctests in quote-based macros
Post Body

Github | Crates.io | Docs.rs

Quote doesn't seem to support string interpolation in doc attributes, so I made this little helper to generate doctests.

UPDATE: 0.2 is now out with many improvements. It now uses 'prettyplease' by default for formatting and can handle blank lines and comments in the doc test.

Here is an example of usage:

``rust // Takes anyTokenStreamas input (but typicallyquote` would be used) let test = doc_test!(quote! { _comment!("Calling fibonacci with 10 returns 55"); assert_eq!(fibonacci(10), 55);

    _blank!();
    _comment!("Calling fibonacci with 1 simply returns 1");
    assert_eq!(fibonacci(1), 1);
}).unwrap();

let comment = doc_comment("This compares between fib inputs and outputs:\n\n").unwrap();

// Interpolates into a regular `quote` invocation
let actual = quote! {
    #comment
    #test
    fn fibonacci(n: u64) -> u64 {
        match n {
            0 => 1,
            1 => 1,
            n => fibonacci(n - 1)   fibonacci(n - 2),
        }
    }
};

```

It generates this:

rust let expected = quote! { /// This compares between fib inputs and outputs: /// /// /// // Calling fibonacci with 10 returns 55 /// assert_eq!(fibonacci(10), 55); /// /// // Calling fibonacci with 1 simply returns 1 /// assert_eq!(fibonacci(1), 1); /// fn fibonacci(n: u64) -> u64 { match n { 0 => 1, 1 => 1, n => fibonacci(n - 1) fibonacci(n - 2), } } };

Author
Account Strength
90%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
2,263
Link Karma
352
Comment Karma
1,891
Profile updated: 16 hours ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago