You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I'm aware it's currently not possible to convert the String type into it's Bytes counterpart. This limits the usefulness of String significantly. Would love to see this feature added.
pub fn string_to_bytes(str1: String) -> Bytes {
let env = Env::default();
let str_len = str1.len() as usize;
// how large should this buffer be?
let mut slice: [u8; 100000] = [0; 100000];
str1.copy_into_slice(&mut slice[..str_len]);
Bytes::from_slice(&env, &slice[0..str_len])
}
Oh that would be handy! I needed this like now and this snippet works great. I just added some input validation in it to check for a max length of like 64.
As far as I'm aware it's currently not possible to convert the
String
type into it's Bytes counterpart. This limits the usefulness ofString
significantly. Would love to see this feature added.Discord context: https://discord.com/channels/897514728459468821/1201650246573367407
The text was updated successfully, but these errors were encountered: