Skip to content

Instantly share code, notes, and snippets.

@kondrak
Created December 11, 2015 08:38
Show Gist options
  • Save kondrak/b7351f11ce8b5950d423 to your computer and use it in GitHub Desktop.
Save kondrak/b7351f11ce8b5950d423 to your computer and use it in GitHub Desktop.
/ ** This doesn't work ** /
//let class_name = to_wstring("minifb_window");
/ ** However calling to_wstring() code not from within external function DOES! **/
let v: Vec<u16> = OsStr::new("minifb_window").encode_wide().chain(Some(0).into_iter()).collect();
let class_name = v.as_ptr();
Possible explanation (see definition of as_ptr()): https://doc.rust-lang.org/std/vec/struct.Vec.html
"The caller must ensure that the slice outlives the pointer this function returns, or else it will end up pointing to garbage."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment