Using .to_string() will allocate String on heap. Usually it's not any issue, but if you wish to avoid this and want to get &str slice directly, you may alternatively use
let mut tmp = [0u8; 4]; let your_string = c.encode_utf8(&mut tmp)); Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack Internal Using .to_string() will allocate String on heap. Usually it's not any issue, but if you wish to avoid this and want to get &str slice directly, you may alternatively use
let mut tmp = [0u8; 4]; let your_string = c.encode_utf8(&mut tmp)); Using .to_string() will allocate String on heap. Usually it's not any issue, but if you wish to avoid this and want to get &str slice directly, you may alternatively use
let mut tmp = [0u8; 4]; let your_string = c.encode_utf8(&mut tmp)); Using .to_string() will allocate String on heap. Usually it's not any issue, but if you wish to avoid this and want to get &str slice directly, you may alternatively use
let mut tmp = [0u8; 4]; let your_string = c.encode_utf8(&mut tmp);