split

Function split 

Source
pub fn split(content: &[u8], size: usize) -> (&[u8], &[u8])
Expand description

Splits a byte slice at the given position, clamping to the slice length.

This is a helper function for parsing binary data that safely handles cases where the requested split position exceeds the slice length.

§Arguments

  • content - The byte slice to split
  • size - The position at which to split (clamped to content.len())

§Returns

A tuple of (left, right) where:

  • left contains bytes [0..min(size, len))
  • right contains the remaining bytes

§Example

use stem_rs::client::datatype::split;

let data = b"hello";
let (left, right) = split(data, 2);
assert_eq!(left, b"he");
assert_eq!(right, b"llo");

// Size exceeds length - returns entire slice and empty remainder
let (left, right) = split(data, 100);
assert_eq!(left, b"hello");
assert_eq!(right, b"");