From 09cedcadbac6e011ba2694926d9eca8113b046d0 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 7 Sep 2016 09:39:08 +0800 Subject: [PATCH] Make rules and declarations parsers take &mut self --- Cargo.toml | 2 +- src/rules_and_declarations.rs | 12 ++++++------ src/tests.rs | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a1ea99cb..3a59de28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cssparser" -version = "0.6.0" +version = "0.7.0" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3" diff --git a/src/rules_and_declarations.rs b/src/rules_and_declarations.rs index 5b72ec3f..9ccc140e 100644 --- a/src/rules_and_declarations.rs +++ b/src/rules_and_declarations.rs @@ -69,7 +69,7 @@ pub trait DeclarationParser { /// If `!important` can be used in a given context, /// `input.try(parse_important).is_ok()` should be used at the end /// of the implementation of this method and the result should be part of the return value. - fn parse_value(&self, name: &str, input: &mut Parser) -> Result; + fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result; } @@ -106,7 +106,7 @@ pub trait AtRuleParser { /// The given `input` is a "delimited" parser /// that ends wherever the prelude should end. /// (Before the next semicolon, the next `{`, or the end of the current block.) - fn parse_prelude(&self, name: &str, input: &mut Parser) + fn parse_prelude(&mut self, name: &str, input: &mut Parser) -> Result, ()> { let _ = name; let _ = input; @@ -121,7 +121,7 @@ pub trait AtRuleParser { /// /// This is only called when `parse_prelude` returned `WithBlock` or `OptionalBlock`, /// and a block was indeed found following the prelude. - fn parse_block(&self, prelude: Self::Prelude, input: &mut Parser) + fn parse_block(&mut self, prelude: Self::Prelude, input: &mut Parser) -> Result { let _ = prelude; let _ = input; @@ -132,7 +132,7 @@ pub trait AtRuleParser { /// /// Convert the prelude into the finished representation of the at-rule /// as returned by `RuleListParser::next` or `DeclarationListParser::next`. - fn rule_without_block(&self, prelude: Self::Prelude) -> Self::AtRule { + fn rule_without_block(&mut self, prelude: Self::Prelude) -> Self::AtRule { let _ = prelude; panic!("The `AtRuleParser::rule_without_block` method must be overriden \ if `AtRuleParser::parse_prelude` ever returns `AtRuleType::OptionalBlock`.") @@ -166,7 +166,7 @@ pub trait QualifiedRuleParser { /// /// The given `input` is a "delimited" parser /// that ends where the prelude should end (before the next `{`). - fn parse_prelude(&self, input: &mut Parser) -> Result { + fn parse_prelude(&mut self, input: &mut Parser) -> Result { let _ = input; Err(()) } @@ -176,7 +176,7 @@ pub trait QualifiedRuleParser { /// Return the finished representation of the qualified rule /// as returned by `RuleListParser::next`, /// or `Err(())` to ignore the entire at-rule as invalid. - fn parse_block(&self, prelude: Self::Prelude, input: &mut Parser) + fn parse_block(&mut self, prelude: Self::Prelude, input: &mut Parser) -> Result { let _ = prelude; let _ = input; diff --git a/src/tests.rs b/src/tests.rs index 1c2cc8e7..e2623869 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -583,7 +583,7 @@ struct JsonParser; impl DeclarationParser for JsonParser { type Declaration = Json; - fn parse_value(&self, name: &str, input: &mut Parser) -> Result { + fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result { let mut value = vec![]; let mut important = false; loop { @@ -622,7 +622,7 @@ impl AtRuleParser for JsonParser { type Prelude = Vec; type AtRule = Json; - fn parse_prelude(&self, name: &str, input: &mut Parser) + fn parse_prelude(&mut self, name: &str, input: &mut Parser) -> Result, Json>, ()> { Ok(AtRuleType::OptionalBlock(vec![ "at-rule".to_json(), @@ -631,12 +631,12 @@ impl AtRuleParser for JsonParser { ])) } - fn parse_block(&self, mut prelude: Vec, input: &mut Parser) -> Result { + fn parse_block(&mut self, mut prelude: Vec, input: &mut Parser) -> Result { prelude.push(Json::Array(component_values_to_json(input))); Ok(Json::Array(prelude)) } - fn rule_without_block(&self, mut prelude: Vec) -> Json { + fn rule_without_block(&mut self, mut prelude: Vec) -> Json { prelude.push(Json::Null); Json::Array(prelude) } @@ -646,11 +646,11 @@ impl QualifiedRuleParser for JsonParser { type Prelude = Vec; type QualifiedRule = Json; - fn parse_prelude(&self, input: &mut Parser) -> Result, ()> { + fn parse_prelude(&mut self, input: &mut Parser) -> Result, ()> { Ok(component_values_to_json(input)) } - fn parse_block(&self, prelude: Vec, input: &mut Parser) -> Result { + fn parse_block(&mut self, prelude: Vec, input: &mut Parser) -> Result { Ok(JArray![ "qualified rule", prelude,