bytesbox ::primitives Trait BytesPrimitives Copy item path source pub trait BytesPrimitives {
// Required method
fn to_bytes (&self) -> Vec <u8 >;
}Expand description A trait to convert primitive types into byte representations (Vec<u8>).
This trait is implemented for common primitive types such as u8, u16, i32, f32, etc.
It allows these types to be converted into a byte format for storage in ByteBox.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u32 = 42 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"42" );
Converts the primitive into a Vec<u8> representing its byte form.
The default implementation converts the primitive to its string representation and then to bytes.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u16 = 256 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"256" );
Converts an f32 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: f32 = 3.14 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"3.14" );
Converts an f64 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: f64 = 2.718281828459045 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"2.718281828459045" );
Converts an i8 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: i8 = -128 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"-128" );
Converts an i16 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: i16 = -32768 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"-32768" );
Converts an i32 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: i32 = -2147483648 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"-2147483648" );
Converts an i64 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: i64 = -9223372036854775808 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"-9223372036854775808" );
Converts an isize into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: isize = -1024 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"-1024" );
Converts a u8 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u8 = 255 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"255" );
Converts a u16 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u16 = 65535 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"65535" );
Converts a u32 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u32 = 4294967295 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"4294967295" );
Converts a u64 into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: u64 = 18446744073709551615 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"18446744073709551615" );
Converts a usize into its byte representation.
§ Examples
use bytesbox::primitives::BytesPrimitives;
let num: usize = 1024 ;
let bytes = num.to_bytes();
assert_eq! (bytes, b"1024" );