usage/
usage.rs

1#[allow(unused_imports)]
2use to_binary::{BinaryError, BinaryString};
3
4fn main() {
5    // A Demo For Working With Whitespace
6    work_with_whitespace();
7
8    // Generates A New BinaryString From Hexadecimal
9    let x = generate();
10
11    // Checks Whether The Input Is Binary
12    let check_if_binary: bool = x.assert_binary();
13
14    // Assert Input Is Binary
15    assert_eq!(check_if_binary, true);
16
17    // Retrieve Sizes Of Binary Input (Bits and Bytes)
18    let size_in_bits = x.bits().unwrap();
19    let size_in_bytes = x.bytes().unwrap();
20
21    // Verifies Sizes Of Binary Inputs
22    let verify_bit_length: bool = x.assert_bit_length(size_in_bits);
23    let verify_byte_length: bool = x.assert_byte_length(size_in_bytes);
24
25    // Assert Sizes Are Correct
26    assert_eq!(verify_bit_length, true);
27    assert_eq!(verify_byte_length, true);
28}
29
30fn generate() -> BinaryString {
31    return BinaryString::from_hex("321155ED37271DE1A9C1914A92A5DFE4").unwrap();
32}
33
34fn work_with_whitespace() {
35    // Generate From &str "Hello"
36    let initial = BinaryString::from("Hello");
37
38    // Add Spaces Between Each Byte In The `BinaryString` And Unwraps Result For Error-Checking Using `BinaryError`
39    let spaces = initial.add_spaces().unwrap();
40
41    // Removes All Whitespace In The `BinaryString`
42    let removed_spaces = spaces.remove_spaces();
43
44    // Asserts The Initial Result And The One With Removed Spaces Are The Same
45    assert_eq!(initial, removed_spaces);
46}