Skip to content

Commit

Permalink
feat: add unsinged int to key and json rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChobobDev committed Nov 26, 2022
1 parent bbfcede commit f4232ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/src/data/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub enum Key {
U8(u8),
Decimal(Decimal),
U16(u16),
U32(u32),
U64(u64),
U128(u128),
Bool(bool),
Str(String),
Bytea(Vec<u8>),
Expand All @@ -52,6 +55,9 @@ impl PartialOrd for Key {
(Key::I64(l), Key::I64(r)) => Some(l.cmp(r)),
(Key::U8(l), Key::U8(r)) => Some(l.cmp(r)),
(Key::U16(l), Key::U16(r)) => Some(l.cmp(r)),
(Key::U32(l), Key::U32(r)) => Some(l.cmp(r)),
(Key::U64(l), Key::U64(r)) => Some(l.cmp(r)),
(Key::U128(l), Key::U128(r)) => Some(l.cmp(r)),
(Key::Decimal(l), Key::Decimal(r)) => Some(l.cmp(r)),
(Key::Bool(l), Key::Bool(r)) => Some(l.cmp(r)),
(Key::Str(l), Key::Str(r)) => Some(l.cmp(r)),
Expand Down Expand Up @@ -81,6 +87,9 @@ impl TryFrom<Value> for Key {
I128(v) => Ok(Key::I128(v)),
U8(v) => Ok(Key::U8(v)),
U16(v) => Ok(Key::U16(v)),
U32(v) => Ok(Key::U32(v)),
U64(v) => Ok(Key::U64(v)),
U128(v) => Ok(Key::U128(v)),
Decimal(v) => Ok(Key::Decimal(v)),
Str(v) => Ok(Key::Str(v)),
Bytea(v) => Ok(Key::Bytea(v)),
Expand Down Expand Up @@ -174,6 +183,21 @@ impl Key {
.chain(v.to_be_bytes().iter())
.copied()
.collect::<Vec<_>>(),
Key::U32(v) => [VALUE, 1]
.iter()
.chain(v.to_be_bytes().iter())
.copied()
.collect::<Vec<_>>(),
Key::U64(v) => [VALUE, 1]
.iter()
.chain(v.to_be_bytes().iter())
.copied()
.collect::<Vec<_>>(),
Key::U128(v) => [VALUE, 1]
.iter()
.chain(v.to_be_bytes().iter())
.copied()
.collect::<Vec<_>>(),
Key::Decimal(v) => {
let sign = if v.is_sign_positive() { 1 } else { 0 };
let convert = |v: Decimal| {
Expand Down
5 changes: 5 additions & 0 deletions core/src/data/value/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl TryFrom<Value> for JsonValue {
.map_err(|_| ValueError::UnreachableJsonNumberParseFailure(v.to_string()).into()),
Value::U8(v) => Ok(v.into()),
Value::U16(v) => Ok(v.into()),
Value::U32(v) => Ok(v.into()),
Value::U64(v) => Ok(v.into()),
Value::U128(v)=> JsonNumber::from_str(&v.to_string())
.map(JsonValue::Number)
.map_err(|_| ValueError::UnreachableJsonNumberParseFailure(v.to_string()).into()),
Value::F64(v) => Ok(v.into()),
Value::Decimal(v) => JsonNumber::from_str(&v.to_string())
.map(JsonValue::Number)
Expand Down

0 comments on commit f4232ad

Please sign in to comment.