pub struct Hex { /* private fields */ }
Expand description
It is an object-oriented representation of binary data in hexadecimal format, which can be put into vertices of the graph. You can create it from Rust primitives:
use sodg::Hex;
let d = Hex::from_i64(65534);
assert_eq!("00-00-00-00-00-00-FF-FE", d.print());
Then, you can turn it back to Rust primitives:
use sodg::Hex;
let d = Hex::from_i64(65534);
assert_eq!(65534, d.to_i64().unwrap());
Implementations
sourceimpl Hex
impl Hex
sourcepub fn from_string(d: String) -> Self
pub fn from_string(d: String) -> Self
From String
.
sourcepub fn to_bool(&self) -> Result<bool>
pub fn to_bool(&self) -> Result<bool>
Turn it into bool
.
use sodg::Hex;
let d = Hex::from_vec([0x01].to_vec());
assert_eq!(true, d.to_bool().unwrap());
sourcepub fn to_i64(&self) -> Result<i64>
pub fn to_i64(&self) -> Result<i64>
Turn it into i64
.
use sodg::Hex;
let d = Hex::from_vec([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A].to_vec());
assert_eq!(42, d.to_i64().unwrap());
sourcepub fn to_f64(&self) -> Result<f64>
pub fn to_f64(&self) -> Result<f64>
Turn it into f64
.
use sodg::Hex;
let d = Hex::from_vec([0x40, 0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18].to_vec());
assert_eq!(std::f64::consts::PI, d.to_f64().unwrap());
sourcepub fn to_utf8(&self) -> Result<String>
pub fn to_utf8(&self) -> Result<String>
Turn it into string
.
use sodg::Hex;
let d = Hex::from_vec([0x41, 0x42].to_vec());
assert_eq!("AB", d.to_utf8().unwrap());
sourcepub fn print(&self) -> String
pub fn print(&self) -> String
Turn it into a hexadecimal string.
use sodg::Hex;
let d = Hex::from_vec([0xCA, 0xFE].to_vec());
assert_eq!("CA-FE", d.print());
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Hex
impl<'de> Deserialize<'de> for Hex
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Hex
impl Send for Hex
impl Sync for Hex
impl Unpin for Hex
impl UnwindSafe for Hex
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more