Bytes
struct Bytes
Find the first index of the byte in the bytes.
Find the first index of the byte in the bytes.
Find the first index of the byte in the bytes.
Copy the bytes from the source bytes to the target bytes.
Copy the bytes from the source bytes to the target bytes.
Copy the bytes from the source bytes to the target bytes.
clear
pub fn clear(self)
Clear the bytes.
clear
pub fn clear(self)
Clear the bytes.
Clear the bytes.
Truncate the bytes to the length.
Truncate the bytes to the length.
Truncate the bytes to the length.
Return a part bytes of the bytes.
Return a part bytes of the bytes.
Return a part bytes of the bytes.
let bytes = "hello".bytes();
assert_eq bytes.slice(0, 2).to_string(), "he";
Convert to string, including invalid characters.
Convert to string, including invalid characters.
Convert to string, including invalid characters.
The valid UTF-8 bytes will be converted to string, and invalid UTF-8 bytes, it will be replaced with U+FFFD, e.g. �
let bytes = "hello".bytes();
assert_eq bytes.to_string(), "hello";
Return the length of the bytes.
Return the length of the bytes.
Return the length of the bytes.
use std.io.Bytes;
let bytes = Bytes.new(len: 10);
assert_eq bytes.len(), 10;
Return true
if the bytes is empty.
Return true
if the bytes is empty.
Return true
if the bytes is empty.
operator+:2
pub fn operator+:2(self, b: Bytes): Bytes
operator+:2
pub fn operator+:2(self, b: Bytes): Bytes
Pop a byte from the bytes.
Pop a byte from the bytes.
Pop a byte from the bytes.
Return the byte value, if the bytes is empty, return nil
.
Appends the b
bytes to the a
bytes.
Appends the b
bytes to the a
bytes.
Appends the b
bytes to the a
bytes.
use std.io.Bytes;
let a = Bytes.from_array([104, 101]);
let b = Bytes.from_array([108, 108, 111]);
a.append(b);
assert_eq a, Bytes.from_array([104, 101, 108, 108, 111]);
operator!=:2
pub fn operator!=:2(self, b: Bytes): bool
operator!=:2
pub fn operator!=:2(self, b: Bytes): bool
operator==:2
pub fn operator==:2(self, b: Bytes): bool
operator==:2
pub fn operator==:2(self, b: Bytes): bool
Convert the bytes to int array.
Convert the bytes to int array.
Convert the bytes to int array.
Each element in the array is a byte.
use std.io.Bytes;
let bytes = Bytes.from_array([104, 101, 108, 108, 111]);
assert_eq bytes.to_array(), [104, 101, 108, 108, 111];
from_array
pub fn from_array(array: [int]): Bytes
Create a Bytes
from a int array. The element is a byte must range of 0..255
.
from_array
pub fn from_array(array: [int]): Bytes
Create a Bytes
from a int array. The element is a byte must range of 0..255
.
Create a Bytes
from a int array. The element is a byte must range of 0..255
.
If the value is out of the byte range, will panic.
use std.io.Bytes;
let bytes = Bytes.from_array([104, 101, 108, 108, 111]);
assert_eq bytes.len(), 5;