json-rust icon indicating copy to clipboard operation
json-rust copied to clipboard

Implement `std::ops` for maths

Open maciejhirsz opened this issue 8 years ago • 2 comments

Implement ops traits to make working with numbers easy:

let data = object!{ foo => 10 };

data["foo"] += 1;

assert_eq(data.dump(), r#"{"foo":11}"#);

maciejhirsz avatar Jul 12 '16 07:07 maciejhirsz

~~I keep forgetting, this only works on the same types, so:~~

maciejhirsz avatar Jul 12 '16 12:07 maciejhirsz

I've randomly looked into this again, and I was wrong (or right) about this. The math ops can be implemented for different types the same way PartialEq can be.

maciejhirsz avatar Oct 13 '16 16:10 maciejhirsz