[librsvg] Doc comments for the Parse trait
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Doc comments for the Parse trait
- Date: Wed, 4 Dec 2019 22:22:23 +0000 (UTC)
commit f6cf1eb53c922d4c7cc3235bef2e21bc3a8c86e5
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Dec 4 16:22:15 2019 -0600
Doc comments for the Parse trait
rsvg_internals/src/parsers.rs | 11 +++++++++++
rsvg_internals/src/property_macros.rs | 4 ++--
2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 2d305930..f107bc0a 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -24,11 +24,20 @@ impl<'a> From<BasicParseError<'a>> for ParseError {
}
}
+/// Trait to parse values using `cssparser::Parser`.
pub trait Parse: Sized {
+ /// Error type for parse errors.
type Err;
+ /// Parses a value out of the `parser`.
+ ///
+ /// All value types should implement this for composability.
fn parse(parser: &mut Parser<'_, '_>) -> Result<Self, Self::Err>;
+ /// Convenience function to parse a value out of a `&str`.
+ ///
+ /// This is useful mostly for tests which want to avoid creating a
+ /// `cssparser::Parser` by hand.
fn parse_str(s: &str) -> Result<Self, Self::Err> {
let mut input = ParserInput::new(s);
let mut parser = Parser::new(&mut input);
@@ -40,10 +49,12 @@ pub trait Parse: Sized {
}
}
+/// Extra utility methods for `cssparser::Parser`.
pub trait CssParserExt {
/// Avoid infinities.
fn expect_finite_number(&mut self) -> Result<f32, ValueErrorKind>;
+ /// Consumes a comma if it exists, or does nothing.
fn optional_comma(&mut self);
}
diff --git a/rsvg_internals/src/property_macros.rs b/rsvg_internals/src/property_macros.rs
index 7908d368..547fd069 100644
--- a/rsvg_internals/src/property_macros.rs
+++ b/rsvg_internals/src/property_macros.rs
@@ -24,8 +24,8 @@ pub trait Property<T> {
/// The macro will generate a `StrokeLinejoin` enum with the provided
/// variants. It will generate an `impl Default for StrokeLinejoin`
/// with the provided `default:` value. Finally, it will generate an
-/// `impl Parse for StrokeLinejoin`, from `parsers::Parse`, where
-/// `type Data = ()` and `type Err = ValueErrorKind`.
+/// `impl Parse for StrokeLinejoin`, from `parsers::Parse`, with
+/// `type Err = ValueErrorKind`.
#[macro_export]
macro_rules! make_property {
($computed_values_type: ty,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]