slice
fn slice(Vec<byte> src, int start, int end) -> Vec<byte> Import
Source: use bytes::{slice}; src/bytes.hy Returns a copy of src[start..end] (end exclusive), with both offsets clamped to the buffer.
Parameters#
| Name | Type |
|---|---|
src | Vec<byte> |
start | int |
end | int |
Returns#
Vec<byte>
Contracts#
Checked according to --contracts (see Contracts).
ensures result.len() <= src.len()
ensures start < end || result.len() == 0
Examples#
use bytes::{slice};
use tests::assert;
let b: Vec<byte> = "hello";
assert!(slice(b, 1, 3).len() == 2);
assert!(slice(b, 3, 99).len() == 2);
See also#
region_eq: True whena[ao..ao+n)equalsb[bo..bo+n)(caller guarantees bounds).to_hex: Encodesbufas lowercase hexadecimal, two digits per byte.from_hex: Decodes hexadecimal text (either case) into bytes.concat: Returns a new buffer holdingafollowed byb.eq: Returnstruewhenaandbhave the same length and the same bytes.find_from: Returns the offset of the firstneedleinhayat or afterstart, or-1.find: Returns the offset of the firstneedleinhay, or-1.rfind: Returns the offset of the lastneedleinhay, or-1.