[][src]Struct to_binary::BinaryString

pub struct BinaryString(pub String);

BinaryString (0bString + 0bWString)

This Struct is the Main Struct for Dealing with Binary Strings and Binary Whitespace Strings.

It is a Tuple Struct that only has a Single, Public Field which is a String and can be accessed with self.0.

How To Access The String Field

use to_binary::BinaryString;

// Generate Binary String From &str
let x = BinaryString::from("Hello");

// Access The Public "String" Field And Assign It To bin_string using field
let bin_string: String = x.0;

// Print Out Information
println!("{}",bin_string);

Implementations

impl BinaryString[src]

pub fn from_hex<T: AsRef<[u8]>>(n: T) -> Result<BinaryString, FromHexError>[src]

Takes as input hexadecimal and outputs a Result containing a BinaryString and on Error, FromHexError

impl BinaryString[src]

pub fn assert_binary(&self) -> bool[src]

Asserts The Input Is A Binary String, or a string with only:

  • 0
  • 1

This function is the same as assert_binary_string() just with a different name

pub fn assert_binary_string(&self) -> bool[src]

Asserts the Input Is A Binary String, or a String with only:

  • 0
  • 1
  • No Whitespace

pub fn assert_binary_whitespace(&self) -> bool[src]

Asserts The Input Is A Binary Whitespace String, or a String with only:

  • 0
  • 1
  • whitespace

TODO: Add a check for whitespace to be every 8th character

pub fn assert_bytes(&self) -> bool[src]

Asserts The Input Has (8 * n) bits or contains full bytes using the remainder function

This function calls the bits() method to retrieve the number of bits then does operation % 8 and compares it against 0

pub fn assert_bit_length(&self, len: usize) -> bool[src]

Asserts The Number of Bits In The String

The function bits() is called to compare to the parameter

pub fn assert_byte_length(&self, len: usize) -> bool[src]

Asserts The Number of Bytes In The String

The function bytes() is called to compare to the parameter

pub fn bits(&self) -> Result<usize, BinaryError>[src]

Count number of bits for both a "Binary String" and "Binary Whitespace String" and returns a Result of either a usize or a BinaryError

pub fn bytes(&self) -> Result<usize, BinaryError>[src]

Count number of bytes for both a "Binary String" and "Binary Whitespace String" and returns a Result of either a usize or on error, empty response

pub fn remove_spaces(&self) -> BinaryString[src]

Removes All Whitespace From Binary String And Returns A BinaryString

pub fn add_spaces(&self) -> Result<BinaryString, BinaryError>[src]

Adds Whitespace Between Every Byte (8 bits)

Example Usage

// Imports
use to_binary::{BinaryString,BinaryError};
 
// Generate `BinaryString` from &str "Test String"
let x = BinaryString::from("Test String");
 
// Returns a `BinaryString` With Spaces Between Every Byte (8 bits)
let bin_with_spaces = x.add_spaces().unwrap();
 

Trait Implementations

impl Clone for BinaryString[src]

impl Debug for BinaryString[src]

impl Default for BinaryString[src]

impl Display for BinaryString[src]

impl<'_> From<&'_ [u8]> for BinaryString[src]

impl<'_> From<&'_ str> for BinaryString[src]

impl From<[u8; 32]> for BinaryString[src]

impl From<String> for BinaryString[src]

impl From<Vec<u8>> for BinaryString[src]

impl From<u8> for BinaryString[src]

impl Hash for BinaryString[src]

impl PartialEq<BinaryString> for BinaryString[src]

impl PartialOrd<BinaryString> for BinaryString[src]

impl StructuralPartialEq for BinaryString[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.