Trait bitlab::ExtractBitsFromIntegralTypes
[−]
[src]
pub trait ExtractBitsFromIntegralTypes { fn get_u8(self, start: usize, length: usize) -> Result<u8, &'static str>; fn get_u16(self, start: usize, length: usize) -> Result<u16, &'static str>; fn get_u32(self, start: usize, length: usize) -> Result<u32, &'static str>; fn get_u64(self, start: usize, length: usize) -> Result<u64, &'static str>; fn get_i8(self, start: usize, length: usize) -> Result<i8, &'static str>; fn get_i16(self, start: usize, length: usize) -> Result<i16, &'static str>; fn get_i32(self, start: usize, length: usize) -> Result<i32, &'static str>; fn get_i64(self, start: usize, length: usize) -> Result<i64, &'static str>; }
Defines a number of functions, which extract a range of bits from primitive numeric types (u8, u16, u32 and u64, i8, i16, i32 and i64) and return the result as one of the following types (u8, u16, u32 and u64, i8, i16, i32 and i64) E.g. the a.get_u8(5,3) function extracts the bits 5,6 and 7 of the variable a and returns the result as a u8 variable
Required Methods
fn get_u8(self, start: usize, length: usize) -> Result<u8, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a u8
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 8)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_u16(self, start: usize, length: usize) -> Result<u16, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a u16
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 16)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_u32(self, start: usize, length: usize) -> Result<u32, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a u32
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 32)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_u64(self, start: usize, length: usize) -> Result<u64, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a u64
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 64)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_i8(self, start: usize, length: usize) -> Result<i8, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a i8
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 8)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_i16(self, start: usize, length: usize) -> Result<i16, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a i16
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 16)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_i32(self, start: usize, length: usize) -> Result<i32, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a i32
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 32)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.
fn get_i64(self, start: usize, length: usize) -> Result<i64, &'static str>
Extracts a range of bits and returns a Result object.
On success, the Result contains the desired value as a i64
On error, the Result contains an error message. This may happen if the range is larger than the data source (start + length > 64)
Parameters:
- start (usize) the start position of the bits to be extracted. Zero is the most significant bit
- length (usize) the number of bits to be extracted.