Skip to content

Commit ad74938

Browse files
committed
Demand that ValT must implement Default.
1 parent 1fa88d2 commit ad74938

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

jaq-core/src/val.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub type Range<V> = core::ops::Range<Option<V>>;
2525
pub trait ValT:
2626
Clone
2727
+ Display
28+
+ Default
2829
+ From<bool>
2930
+ From<isize>
3031
+ From<alloc::string::String>

jaq-json/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use hifijson::{LexAlloc, Token};
2222
/// Operations on numbers follow a few principles:
2323
/// * The sum, difference, product, and remainder of two integers is integer.
2424
/// * Any other operation between two numbers yields a float.
25-
#[derive(Clone, Debug)]
25+
#[derive(Clone, Debug, Default)]
2626
pub enum Val {
27+
#[default]
2728
/// Null
2829
Null,
2930
/// Boolean
@@ -185,7 +186,7 @@ impl jaq_core::ValT for Val {
185186
};
186187
match o.entry(Rc::clone(i)) {
187188
Occupied(mut e) => {
188-
let v = core::mem::replace(e.get_mut(), Self::from(false));
189+
let v = core::mem::replace(e.get_mut(), Self::default());
189190
match f(v).next().transpose()? {
190191
Some(y) => e.insert(y),
191192
// this runs in constant time, at the price of
@@ -211,7 +212,7 @@ impl jaq_core::ValT for Val {
211212
Err(e) => return opt.fail(self, |_| Exn::from(e)),
212213
};
213214

214-
let x = core::mem::replace(&mut a[i], Self::from(false));
215+
let x = core::mem::replace(&mut a[i], Self::default());
215216
if let Some(y) = f(x).next().transpose()? {
216217
a[i] = y;
217218
} else {

0 commit comments

Comments
 (0)