summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/func.rs2
-rw-r--r--src/eval/methods.rs4
-rw-r--r--src/eval/mod.rs4
-rw-r--r--src/eval/module.rs2
-rw-r--r--src/eval/str.rs2
-rw-r--r--src/eval/symbol.rs2
-rw-r--r--src/eval/value.rs17
7 files changed, 14 insertions, 19 deletions
diff --git a/src/eval/func.rs b/src/eval/func.rs
index 08296320..e1472cca 100644
--- a/src/eval/func.rs
+++ b/src/eval/func.rs
@@ -115,7 +115,7 @@ impl Func {
}
Repr::With(arc) => {
args.items = arc.1.items.iter().cloned().chain(args.items).collect();
- return arc.0.call_vm(vm, args);
+ arc.0.call_vm(vm, args)
}
}
}
diff --git a/src/eval/methods.rs b/src/eval/methods.rs
index 72245fb0..bfe9b0e4 100644
--- a/src/eval/methods.rs
+++ b/src/eval/methods.rs
@@ -27,7 +27,7 @@ pub fn call(
},
Value::Str(string) => match method {
- "len" => Value::Int(string.len() as i64),
+ "len" => Value::Int(string.len()),
"first" => Value::Str(string.first().at(span)?),
"last" => Value::Str(string.last().at(span)?),
"at" => Value::Str(string.at(args.expect("index")?).at(span)?),
@@ -73,7 +73,7 @@ pub fn call(
Value::Content(content) => match method {
"func" => content.func().into(),
"has" => Value::Bool(content.has(&args.expect::<EcoString>("field")?)),
- "at" => content.at(&args.expect::<EcoString>("field")?).at(span)?.clone(),
+ "at" => content.at(&args.expect::<EcoString>("field")?).at(span)?,
"location" => content
.location()
.ok_or("this method can only be called on content returned by query(..)")
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index f19e4305..8790bc18 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -652,7 +652,7 @@ impl Eval for ast::MathIdent {
type Output = Value;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok(vm.scopes.get_in_math(self).cloned().at(self.span())?)
+ vm.scopes.get_in_math(self).cloned().at(self.span())
}
}
@@ -700,7 +700,7 @@ impl Eval for ast::Ident {
type Output = Value;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok(vm.scopes.get(self).cloned().at(self.span())?)
+ vm.scopes.get(self).cloned().at(self.span())
}
}
diff --git a/src/eval/module.rs b/src/eval/module.rs
index e911d859..feb5a14b 100644
--- a/src/eval/module.rs
+++ b/src/eval/module.rs
@@ -60,7 +60,7 @@ impl Module {
/// Try to access a definition in the module.
pub fn get(&self, name: &str) -> StrResult<&Value> {
- self.scope().get(&name).ok_or_else(|| {
+ self.scope().get(name).ok_or_else(|| {
eco_format!("module `{}` does not contain `{name}`", self.name())
})
}
diff --git a/src/eval/str.rs b/src/eval/str.rs
index b1551564..d867e19c 100644
--- a/src/eval/str.rs
+++ b/src/eval/str.rs
@@ -118,7 +118,7 @@ impl Str {
/// The text of the pattern's first match in this string.
pub fn find(&self, pattern: StrPattern) -> Option<Self> {
match pattern {
- StrPattern::Str(pat) => self.0.contains(pat.as_str()).then(|| pat),
+ StrPattern::Str(pat) => self.0.contains(pat.as_str()).then_some(pat),
StrPattern::Regex(re) => re.find(self).map(|m| m.as_str().into()),
}
}
diff --git a/src/eval/symbol.rs b/src/eval/symbol.rs
index d15d5a79..5c8951b1 100644
--- a/src/eval/symbol.rs
+++ b/src/eval/symbol.rs
@@ -70,7 +70,7 @@ impl Symbol {
modifiers.push('.');
}
modifiers.push_str(modifier);
- if find(list.variants(), &modifiers).is_some() {
+ if find(list.variants(), modifiers).is_some() {
return Ok(self);
}
}
diff --git a/src/eval/value.rs b/src/eval/value.rs
index bf1dd18a..517cadc5 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -17,9 +17,10 @@ use crate::model::Styles;
use crate::syntax::{ast, Span};
/// A computational value.
-#[derive(Clone)]
+#[derive(Clone, Default)]
pub enum Value {
/// The value that indicates the absence of a meaningful value.
+ #[default]
None,
/// A value that indicates some smart default behaviour.
Auto,
@@ -122,10 +123,10 @@ impl Value {
/// Try to access a field on the value.
pub fn field(&self, field: &str) -> StrResult<Value> {
match self {
- Self::Symbol(symbol) => symbol.clone().modified(&field).map(Self::Symbol),
- Self::Dict(dict) => dict.at(&field).cloned(),
- Self::Content(content) => content.at(&field),
- Self::Module(module) => module.get(&field).cloned(),
+ Self::Symbol(symbol) => symbol.clone().modified(field).map(Self::Symbol),
+ Self::Dict(dict) => dict.at(field).cloned(),
+ Self::Content(content) => content.at(field),
+ Self::Module(module) => module.get(field).cloned(),
v => Err(eco_format!("cannot access fields on type {}", v.type_name())),
}
}
@@ -168,12 +169,6 @@ impl Value {
}
}
-impl Default for Value {
- fn default() -> Self {
- Value::None
- }
-}
-
impl Debug for Value {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {