Skip to content

Commit 25f7424

Browse files
committed
Add Integer::as_signed Integer::as_unsigned
1 parent f026ad4 commit 25f7424

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "msgpacker"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
authors = ["Victor Lopez <victor@codx.io>"]
55
categories = ["compression", "encoding", "parser-implementations"]
66
edition = "2021"

src/integer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ impl Integer {
3636
Self::Int64(n.into())
3737
}
3838

39+
/// Return either a raw i64 or a cast u64
40+
pub const fn as_signed(&self) -> i64 {
41+
match self {
42+
Self::Uint64(i) => *i as i64,
43+
Self::Int64(i) => *i,
44+
}
45+
}
46+
47+
/// Return either a raw u64 or a cast i64
48+
pub const fn as_unsigned(&self) -> u64 {
49+
match self {
50+
Self::Uint64(i) => *i,
51+
Self::Int64(i) => *i as u64,
52+
}
53+
}
54+
3955
/// Return the underlying u64, if the number if unsigned
4056
pub const fn as_u64(&self) -> Option<u64> {
4157
match self {

0 commit comments

Comments
 (0)