Skip to content

Commit 626100d

Browse files
committed
Add Parser::try_parse, same as Parser::try
Fixes servo#243
1 parent dd75c5d commit 626100d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.25.3"
3+
version = "0.25.4"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/parser.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,19 @@ impl<'i: 't, 't> Parser<'i, 't> {
495495
self.input.tokenizer.seen_var_or_env_functions()
496496
}
497497

498+
/// The old name of `try_parse`, which requires raw identifiers in the Rust 2018 edition.
499+
#[inline]
500+
pub fn try<F, T, E>(&mut self, thing: F) -> Result<T, E>
501+
where F: FnOnce(&mut Parser<'i, 't>) -> Result<T, E> {
502+
self.try_parse(thing)
503+
}
504+
498505
/// Execute the given closure, passing it the parser.
499506
/// If the result (returned unchanged) is `Err`,
500507
/// the internal state of the parser (including position within the input)
501508
/// is restored to what it was before the call.
502509
#[inline]
503-
pub fn try<F, T, E>(&mut self, thing: F) -> Result<T, E>
510+
pub fn try_parse<F, T, E>(&mut self, thing: F) -> Result<T, E>
504511
where F: FnOnce(&mut Parser<'i, 't>) -> Result<T, E> {
505512
let start = self.state();
506513
let result = thing(self);

0 commit comments

Comments
 (0)