Skip to main content

to_bytes

Function to_bytes 

Source
pub const fn to_bytes<S: IsTStr>(_: S) -> &'static [u8]
Expand description

Converts an IsTStr to an utf8-encoded &'static [u8]

This is a non-associated function for const compatibility, the (non-const) trait method equivalent of this is IsTStr::to_bytes

ยงExample

use tstr::{TStr, ts};

let foo: TStr<_> = ts!(foo);
assert_eq!(tstr::to_bytes(foo), "foo".as_bytes());

const BAR_STR: &[u8] = tstr::to_bytes(ts!("bar"));
assert_eq!(BAR_STR, "bar".as_bytes());