Merge pull request #378 from dtolnay/doc
Document Synom::description()
diff --git a/src/synom.rs b/src/synom.rs
index a7dd13c..f631f8b 100644
--- a/src/synom.rs
+++ b/src/synom.rs
@@ -167,6 +167,33 @@
pub trait Synom: Sized {
fn parse(input: Cursor) -> PResult<Self>;
+ /// A short name of the type being parsed.
+ ///
+ /// The description should only be used for a simple name. It should not
+ /// contain newlines or sentence-ending punctuation, to facilitate embedding in
+ /// larger user-facing strings. Syn will use this description when building
+ /// error messages about parse failures.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// # use syn::buffer::Cursor;
+ /// # use syn::synom::{Synom, PResult};
+ /// #
+ /// struct ExprForLoop {
+ /// // ...
+ /// }
+ ///
+ /// impl Synom for ExprForLoop {
+ /// # fn parse(input: Cursor) -> PResult<Self> { unimplemented!() }
+ /// // fn parse(...) -> ... { ... }
+ ///
+ /// fn description() -> Option<&'static str> {
+ /// // will result in messages like "failed to parse `for` loop: $reason"
+ /// Some("`for` loop")
+ /// }
+ /// }
+ /// ```
fn description() -> Option<&'static str> {
None
}