style: Document the error_reporting module.

This commit is contained in:
Emilio Cobos Álvarez 2016-12-31 15:00:52 +01:00
parent 4108ff8383
commit 858ee1f1ec
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -4,14 +4,27 @@
//! Types used to report parsing errors. //! Types used to report parsing errors.
#![deny(missing_docs)]
use cssparser::{Parser, SourcePosition}; use cssparser::{Parser, SourcePosition};
use log; use log;
/// A generic trait for an error reporter.
pub trait ParseErrorReporter { pub trait ParseErrorReporter {
/// Called the style engine detects an error.
///
/// Returns the current input being parsed, the source position it was
/// reported from, and a message.
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str); fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str);
/// Clone this error reporter.
///
/// TODO(emilio): I'm pretty sure all the box shenanigans can go away.
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync>; fn clone(&self) -> Box<ParseErrorReporter + Send + Sync>;
} }
/// An error reporter that reports the errors to the `info` log channel.
///
/// TODO(emilio): The name of this reporter is a lie, and should be renamed!
pub struct StdoutErrorReporter; pub struct StdoutErrorReporter;
impl ParseErrorReporter for StdoutErrorReporter { impl ParseErrorReporter for StdoutErrorReporter {
fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str) { fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str) {