Skip to content

Commit c305bcf

Browse files
committed
Return &CowRcStr instead of CowRcStr in some Parser::expect_* methods
1 parent a79e536 commit c305bcf

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/parser.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ impl<'i: 't, 't> Parser<'i, 't> {
486486

487487
/// Parse a <ident-token> and return the unescaped value.
488488
#[inline]
489-
pub fn expect_ident(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
489+
pub fn expect_ident(&mut self) -> Result<&CowRcStr<'i>, BasicParseError<'i>> {
490490
match *self.next()? {
491-
Token::Ident(ref value) => Ok(value.clone()),
491+
Token::Ident(ref value) => Ok(value),
492492
ref t => Err(BasicParseError::UnexpectedToken(t.clone()))
493493
}
494494
}
@@ -504,19 +504,19 @@ impl<'i: 't, 't> Parser<'i, 't> {
504504

505505
/// Parse a <string-token> and return the unescaped value.
506506
#[inline]
507-
pub fn expect_string(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
507+
pub fn expect_string(&mut self) -> Result<&CowRcStr<'i>, BasicParseError<'i>> {
508508
match *self.next()? {
509-
Token::QuotedString(ref value) => Ok(value.clone()),
509+
Token::QuotedString(ref value) => Ok(value),
510510
ref t => Err(BasicParseError::UnexpectedToken(t.clone()))
511511
}
512512
}
513513

514514
/// Parse either a <ident-token> or a <string-token>, and return the unescaped value.
515515
#[inline]
516-
pub fn expect_ident_or_string(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
516+
pub fn expect_ident_or_string(&mut self) -> Result<&CowRcStr<'i>, BasicParseError<'i>> {
517517
match *self.next()? {
518-
Token::Ident(ref value) => Ok(value.clone()),
519-
Token::QuotedString(ref value) => Ok(value.clone()),
518+
Token::Ident(ref value) => Ok(value),
519+
Token::QuotedString(ref value) => Ok(value),
520520
ref t => Err(BasicParseError::UnexpectedToken(t.clone()))
521521
}
522522
}
@@ -530,7 +530,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
530530
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {}
531531
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()))
532532
}
533-
self.parse_nested_block(|input| input.expect_string().map_err(ParseError::Basic))
533+
self.parse_nested_block(|input| input.expect_string().map_err(ParseError::Basic).map(|s| s.clone()))
534534
.map_err(ParseError::<()>::basic)
535535
}
536536

@@ -544,7 +544,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
544544
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {}
545545
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()))
546546
}
547-
self.parse_nested_block(|input| input.expect_string().map_err(ParseError::Basic))
547+
self.parse_nested_block(|input| input.expect_string().map_err(ParseError::Basic).map(|s| s.clone()))
548548
.map_err(ParseError::<()>::basic)
549549
}
550550

@@ -651,9 +651,9 @@ impl<'i: 't, 't> Parser<'i, 't> {
651651
///
652652
/// If the result is `Ok`, you can then call the `Parser::parse_nested_block` method.
653653
#[inline]
654-
pub fn expect_function(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
654+
pub fn expect_function(&mut self) -> Result<&CowRcStr<'i>, BasicParseError<'i>> {
655655
match *self.next()? {
656-
Token::Function(ref name) => Ok(name.clone()),
656+
Token::Function(ref name) => Ok(name),
657657
ref t => Err(BasicParseError::UnexpectedToken(t.clone()))
658658
}
659659
}

src/rules_and_declarations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub fn parse_one_declaration<'i, 't, P, E>(input: &mut Parser<'i, 't>, parser: &
380380
where P: DeclarationParser<'i, Error = E> {
381381
let start_position = input.position();
382382
input.parse_entirely(|input| {
383-
let name = input.expect_ident()?;
383+
let name = input.expect_ident()?.clone();
384384
input.expect_colon()?;
385385
parser.parse_value(name, input)
386386
}).map_err(|e| PreciseParseError {

0 commit comments

Comments
 (0)