vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Length-field encoder for wire-format sequences.

use super::put_u32;

/// Append a little-endian `u32` length converted from `usize`.
///
/// # Errors
///
/// Returns an actionable error when `value` cannot fit in the wire-format
/// length field.
#[inline]
pub fn put_len_u32(out: &mut Vec<u8>, value: usize, label: &str) -> Result<(), String> {
    let encoded = u32::try_from(value).map_err(|error| {
        format!("{label} {value} exceeds u32::MAX: {error}. Fix: split the Program before IR wire-format serialization.")
    })?;
    put_u32(out, encoded);
    Ok(())
}