pub struct DecSixbit { /* private fields */ }Expand description
The DecSixbit struct stores the encoded bytes and provides methods
for accessing the encoded data and retrieving the original string.
Implementations§
Source§impl DecSixbit
impl DecSixbit
Sourcepub fn new(str: &str) -> Result<Self, Error>
pub fn new(str: &str) -> Result<Self, Error>
Creates a new DecSixbit instance by encoding the input string.
Only accepts ASCII characters in the range 32-95 (space through underscore).
Creates a new DecSixbit instance by encoding the input string.
§Parameters
str: The input string to encode. Must contain only ASCII characters in the range 32-95.
§Errors
Returns an Error::InvalidCharacter if the input contains invalid characters.
§Examples
use dec_sixbit::DecSixbit;
let sixbit = DecSixbit::new("HELLO").unwrap();Sourcepub fn try_from_slice(bytes: &[u8]) -> Result<Self, Error>
pub fn try_from_slice(bytes: &[u8]) -> Result<Self, Error>
Sourcepub fn from_slice(bytes: &[u8]) -> Self
pub fn from_slice(bytes: &[u8]) -> Self
Sourcepub fn get(&self, index: usize) -> Option<char>
pub fn get(&self, index: usize) -> Option<char>
Gets the character at the specified position.
§Parameters
index: The position of the character to retrieve.
§Returns
An Option<char> which is Some(char) if the index is valid, or None otherwise.
§Examples
use dec_sixbit::DecSixbit;
let sixbit = DecSixbit::new("HELLO").unwrap();
assert_eq!(sixbit.get(1), Some('E'));
assert_eq!(sixbit.get(5), None);Sourcepub fn starts_with<P: AsRef<str>>(&self, prefix: P) -> bool
pub fn starts_with<P: AsRef<str>>(&self, prefix: P) -> bool
Checks if the string starts with the given prefix.
§Parameters
prefix: The prefix string to check.
§Returns
true if the string starts with the given prefix, otherwise false.
§Examples
use dec_sixbit::DecSixbit;
let sixbit = DecSixbit::new("HELLO").unwrap();
assert!(sixbit.starts_with("HE"));
assert!(!sixbit.starts_with("EL"));Sourcepub fn ends_with<P: AsRef<str>>(&self, suffix: P) -> bool
pub fn ends_with<P: AsRef<str>>(&self, suffix: P) -> bool
Checks if the string ends with the given suffix.
§Parameters
suffix: The suffix string to check.
§Returns
true if the string ends with the given suffix, otherwise false.
§Examples
use dec_sixbit::DecSixbit;
let sixbit = DecSixbit::new("HELLO").unwrap();
assert!(sixbit.ends_with("LO"));
assert!(!sixbit.ends_with("HE"));Sourcepub fn contains<P: AsRef<str>>(&self, substring: P) -> bool
pub fn contains<P: AsRef<str>>(&self, substring: P) -> bool
Checks if the string contains the given substring.
§Parameters
substring: The substring to search for.
§Returns
true if the string contains the given substring, otherwise false.
§Examples
use dec_sixbit::DecSixbit;
let sixbit = DecSixbit::new("HELLO").unwrap();
assert!(sixbit.contains("ELL"));
assert!(!sixbit.contains("XYZ"));