Function elma::string_null_pad [] [src]

pub fn string_null_pad(name: &str, pad: usize) -> Result<Vec<u8>, ElmaError>

Pads a string with null bytes.

Examples

When converting strings to bytes for use in an Elma file, you need to pad it to a certain length depending on the field. This function creates a new zero-filled vector to pad size, then fills in the string.

let string = String::from("Elma");
let padded = elma::string_null_pad(&string, 10).unwrap();
assert_eq!(&padded, &[0x45, 0x6C, 0x6D, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);