daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![feature(in_band_lifetimes)]
  2.  
  3. fn main() {
  4.     println!("Hello, {}", char_to_str('😊').as_ref());
  5. }
  6.  
  7. struct Str {
  8.     inner: [u8; 8],
  9. }
  10.  
  11. impl AsRef<str> for Str {
  12.     fn as_ref(&self) -> &str {
  13.         unsafe { std::str::from_utf8_unchecked(&self.inner) }
  14.     }
  15. }
  16.  
  17. fn char_to_str(c: char) -> Str {
  18.     let mut out: [u8; 8] = unsafe { std::mem::zeroed() };
  19.     c.encode_utf8(&mut out);
  20.     Str { inner: out }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top