#422·rust

String tensor vs utf8 encoding

Author: sir-earlCreated Feb 16, 2024Updated Mar 10, 2024
Labelsenhancement

I'm trying to use raw_ops::decode_image to load an image directly from a u8 slice (as opposed to from file as per the example), but it seems I must first convert the slice to a scalar tensor string.

It appears I can make this work with something like:

let s = unsafe { String::from_utf8_unchecked(image_bytes.to_vec()) };

My concern is that Rust expects all strings to be utf8 encoded, of which the above certainly is not.

Am I missing something obvious? Is there a better way to approach this?