replace .get(0) with .first()

This commit is contained in:
Connor Skees 2020-08-05 03:09:10 -04:00
parent df1456f9b1
commit 61ef52eb3f
5 changed files with 9 additions and 9 deletions

View File

@ -33,7 +33,7 @@ fn simple_selectors(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<V
}
let compound = if let Some(ComplexSelectorComponent::Compound(compound)) =
selector.0.components[0].components.get(0).cloned()
selector.0.components[0].components.first().cloned()
{
compound
} else {

View File

@ -129,8 +129,8 @@ impl Css {
for rule in body {
match rule {
Stmt::RuleSet { .. } => vals.extend(self.parse_stmt(rule)?),
Stmt::Style(s) => vals.get_mut(0).unwrap().push_style(s),
Stmt::Comment(s) => vals.get_mut(0).unwrap().push_comment(s),
Stmt::Style(s) => vals.first_mut().unwrap().push_style(s),
Stmt::Comment(s) => vals.first_mut().unwrap().push_comment(s),
Stmt::Media(m) => {
let MediaRule { query, body, .. } = *m;
vals.push(Toplevel::Media { query, body })
@ -167,7 +167,7 @@ impl Css {
k @ Stmt::KeyframesRuleSet(..) => {
unreachable!("@keyframes ruleset {:?}", k)
}
Stmt::Import(s) => vals.get_mut(0).unwrap().push_import(s),
Stmt::Import(s) => vals.first_mut().unwrap().push_import(s),
};
}
vals
@ -204,7 +204,7 @@ impl Css {
let mut vals = vec![Toplevel::new_keyframes_rule(selector)];
for rule in body {
match rule {
Stmt::Style(s) => vals.get_mut(0).unwrap().push_style(s),
Stmt::Style(s) => vals.first_mut().unwrap().push_style(s),
Stmt::KeyframesRuleSet(..) => vals.extend(self.parse_stmt(rule)?),
_ => todo!(),
}
@ -221,7 +221,7 @@ impl Css {
// this is how we print newlines between unrelated styles
// it could probably be refactored
if !v.is_empty() {
if let Some(Toplevel::MultilineComment(..)) = v.get(0) {
if let Some(Toplevel::MultilineComment(..)) = v.first() {
} else if is_first {
is_first = false;
} else {

View File

@ -105,7 +105,7 @@ impl<'a> Parser<'a> {
comma_separated.push(space_separated.pop().unwrap());
} else {
let mut span = space_separated
.get(0)
.first()
.ok_or(("Expected expression.", val.span))?
.span;
comma_separated.push(

View File

@ -561,7 +561,7 @@ fn is_simple_selector_start(c: char) -> bool {
/// with pseudo-class syntax (`:before`, `:after`, `:first-line`, or
/// `:first-letter`)
fn is_fake_pseudo_element(name: &str) -> bool {
match name.as_bytes().get(0) {
match name.as_bytes().first() {
Some(b'a') | Some(b'A') => name.to_ascii_lowercase() == "after",
Some(b'b') | Some(b'B') => name.to_ascii_lowercase() == "before",
Some(b'f') | Some(b'F') => match name.to_ascii_lowercase().as_str() {

View File

@ -364,7 +364,7 @@ impl SimpleSelector {
};
complex
.components
.get(0)
.first()
.unwrap()
.as_compound()
.components