u8
Expand description
8-bit unsigned integer
Implementations
fn min() -> Self
fn min() -> Self
The smallest value that can be represented by this integer type.
Returns
- [u8] - The smallest
u8
value.
Examples
fn foo() {
let val = u8::min();
assert(val == 0u8);
}
fn max() -> Self
fn max() -> Self
The largest value that can be represented by this integer type,
28 - 1.
Returns
- [u8] - The largest
u8
value.
Examples
fn foo() {
let val = u8::max();
assert(val == 255u8);
}
fn bits() -> u64
fn bits() -> u64
The size of this integer type in bits.
Returns
- [u64] - The number of bits for a
u8
.
Examples
fn foo() {
let bits = u8::bits();
assert(bits == 8);
}
fn zero() -> Self
fn zero() -> Self
Returns
- [u8] -> The zero value for the
u8
type.
Examples
fn foo() {
let zero_u8 = u8::zero();
assert(zero_u8 == 0u8);
}
fn as_u16(self) -> u16
fn as_u16(self) -> u16
Extends a u8
to a u16
.
Returns
- [u16] - The converted
u8
value.
Examples
fn foo() {
let val = 2u8;
let result = val.as_u16();
assert(result == 2u16);
}
fn as_u32(self) -> u32
fn as_u32(self) -> u32
Extends a u8
to a u32
.
Returns
- [u32] - The converted
u8
value.
Examples
fn foo() {
let val = 2u8;
let result = val.as_u32();
assert(result == 2u32);
}
fn as_u64(self) -> u64
fn as_u64(self) -> u64
Extends a u8
to a u64
.
Returns
- [u64] - The converted
u8
value.
Examples
fn foo() {
let val = 2u8;
let result = val.as_u64();
assert(result == 2);
}
fn as_u256(self) -> u256
fn as_u256(self) -> u256
Extends a u8
to a u256
.
Returns
- [u256] - The converted
u8
value.
Examples
fn foo() {
let val = 2u8;
let result = val.as_u256();
assert(result == 0x0000000000000000000000000000000000000000000000000000000000000002u256);
}
Trait Implementations
impl Eq for u8
impl Eq for u8
fn eq(self, other: Self) -> bool
fn neq(self, other: Self) -> bool
fn neq(self, other: Self) -> bool
Evaluates if two values of the same type are not equal.
Additional Information
This function is inherited when eq()
is implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
if the two values are not equal, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 2 };
let result = struct1 != struct2;
assert(result);
}
impl BitwiseAnd for u8
impl BitwiseAnd for u8
fn binary_and(self, other: Self) -> Self
impl BitwiseXor for u8
impl BitwiseXor for u8
fn binary_xor(self, other: Self) -> Self
impl OrdEq for u8
impl OrdEq for u8
fn ge(self, other: Self) -> bool
fn ge(self, other: Self) -> bool
Evaluates if one value of the same type is greater or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is greater than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn gt(self, other: Self) -> bool {
self.val > other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 >= struct2;
assert(result);
}
fn le(self, other: Self) -> bool
fn le(self, other: Self) -> bool
Evaluates if one value of the same type is less or equal to than another.
Additional Information
This trait requires that the Ord
and Eq
traits are implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
ifself
is less than or equal toother
, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl Eq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
impl Ord for MyStruct {
fn lt(self, other: Self) -> bool {
self.val < other.val
}
}
impl OrdEq for MyStruct {}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 10 };
let result = struct1 <= struct2;
assert(result);
}