Skip to content

Commit

Permalink
Demand that ValT must implement Default.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Oct 10, 2024
1 parent 1fa88d2 commit ad74938
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions jaq-core/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type Range<V> = core::ops::Range<Option<V>>;
pub trait ValT:
Clone
+ Display
+ Default
+ From<bool>
+ From<isize>
+ From<alloc::string::String>
Expand Down
7 changes: 4 additions & 3 deletions jaq-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use hifijson::{LexAlloc, Token};
/// Operations on numbers follow a few principles:
/// * The sum, difference, product, and remainder of two integers is integer.
/// * Any other operation between two numbers yields a float.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub enum Val {
#[default]
/// Null
Null,
/// Boolean
Expand Down Expand Up @@ -185,7 +186,7 @@ impl jaq_core::ValT for Val {
};
match o.entry(Rc::clone(i)) {
Occupied(mut e) => {
let v = core::mem::replace(e.get_mut(), Self::from(false));
let v = core::mem::replace(e.get_mut(), Self::default());
match f(v).next().transpose()? {
Some(y) => e.insert(y),
// this runs in constant time, at the price of
Expand All @@ -211,7 +212,7 @@ impl jaq_core::ValT for Val {
Err(e) => return opt.fail(self, |_| Exn::from(e)),
};

let x = core::mem::replace(&mut a[i], Self::from(false));
let x = core::mem::replace(&mut a[i], Self::default());
if let Some(y) = f(x).next().transpose()? {
a[i] = y;
} else {
Expand Down

0 comments on commit ad74938

Please sign in to comment.