Repository: PistonDevelopers/glfw-rs (language: rust)

Issue:
Fix Message lifetime
```
src/lib.rs:1107:24: 1107:34 error: the parameter type `Message` may not live long enough [E0310]
src/lib.rs:1107 match receiver.try_recv() {
```



Discussion / hints:
Working on this now.


Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 6de82c26..26101bc2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "glfw"
-version = "0.0.3"
+version = "0.0.4"
 authors = ["The glfw-rs developers."]
 description = "GLFW3 bindings and idiomatic wrapper for Rust."
 keywords = ["windowing", "opengl"]
diff --git a/examples/events.rs b/examples/events.rs
index cdf82413..c58932bf 100644
--- a/examples/events.rs
+++ b/examples/events.rs
@@ -60,8 +60,8 @@ fn main() {
 
 fn handle_window_event(window: &mut glfw::Window, (time, event): (f64, glfw::WindowEvent)) {
     match event {
-        glfw::WindowEvent::Pos(x, y)                      => window.set_title(format!("Time: {:?}, Window pos: ({:?}, {:?})", time, x, y).as_slice()),
-        glfw::WindowEvent::Size(w, h)                     => window.set_title(format!("Time: {:?}, Window size: ({:?}, {:?})", time, w, h).as_slice()),
+        glfw::WindowEvent::Pos(x, y)                      => window.set_title(&format!("Time: {:?}, Window pos: ({:?}, {:?})", time, x, y)),
+        glfw::WindowEvent::Size(w, h)                     => window.set_title(&format!("Time: {:?}, Window size: ({:?}, {:?})", time, w, h)),
         glfw::WindowEvent::Close                          => println!("Time: {:?}, Window close requested.", time),
         glfw::WindowEvent::Refresh                        => println!("Time: {:?}, Window refresh callback triggered.", time),
         glfw::WindowEvent::Focus(true)                    => println!("Time: {:?}, Window focus gained.", time),
@@ -71,10 +71,10 @@ fn handle_window_event(window: &mut glfw::Window, (time, event): (f64, glfw::Win
         glfw::WindowEvent::FramebufferSize(w, h)          => println!("Time: {:?}, Framebuffer size: ({:?}, {:?})", time, w, h),
         glfw::WindowEvent::Char(character)                => println!("Time: {:?}, Character: {:?}", time, character),
         glfw::WindowEvent::MouseButton(btn, action, mods) => println!("Time: {:?}, Button: {:?}, Action: {:?}, Modifiers: [{:?}]", time, glfw::DebugAliases(btn), action, mods),
-        glfw::WindowEvent::CursorPos(xpos, ypos)          => window.set_title(format!("Time: {:?}, Cursor position: ({:?}, {:?})", time, xpos, ypos).as_slice()),
+        glfw::WindowEvent::CursorPos(xpos, ypos)          => window.set_title(&format!("Time: {:?}, Cursor position: ({:?}, {:?})", time, xpos, ypos)),
         glfw::WindowEvent::CursorEnter(true)              => println!("Time: {:?}, Cursor entered window.", time),
         glfw::WindowEvent::CursorEnter(false)             => println!("Time: {:?}, Cursor left window.", time),
-        glfw::WindowEvent::Scroll(x, y)                   => window.set_title(format!("Time: {:?}, Scroll offset: ({:?}, {:?})", time, x, y).as_slice()),
+        glfw::WindowEvent::Scroll(x, y)                   => window.set_title(&format!("Time: {:?}, Scroll offset: ({:?}, {:?})", time, x, y)),
         glfw::WindowEvent::Key(key, scancode, action, mods) => {
             println!("Time: {:?}, Key: {:?}, ScanCode: {:?}, Action: {:?}, Modifiers: [{:?}]", time, key, scancode, action, mods);
             match (key, action) {
diff --git a/src/lib.rs b/src/lib.rs
index 538e3d81..b3162040 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,6 +18,8 @@
 #![crate_type = "dylib"]
 #![crate_name = "glfw"]
 
+#![feature(core)]
+#![feature(std_misc)]
 #![feature(unsafe_destructor)]
 
 #![allow(non_upper_case_globals)]
@@ -72,7 +74,7 @@ extern crate bitflags;
 
 use libc::{c_char, c_double, c_float, c_int};
 use libc::{c_ushort, c_void};
-use std::ffi::CString;
+use std::ffi::{CStr, CString};
 use std::mem;
 use std::sync::mpsc::{channel, Receiver, Sender};
 use std::fmt;
@@ -505,7 +507,7 @@ impl Glfw {
             let mut count = 0;
             let ptr = ffi::glfwGetMonitors(&mut count);
             f(self,
-              slice::from_raw_buf(&(ptr as *const _), count as usize).iter().map(|&ptr| {
+              slice::from_raw_parts(ptr as *const _, count as usize).iter().map(|&ptr| {
                 Monitor {
                     ptr: ptr
                 }
@@ -732,14 +734,13 @@ pub fn get_version() -> Version {
 
 /// Replacement for `String::from_raw_buf`
 pub unsafe fn string_from_c_str(c_str: *const c_char) -> String {
-    use std::ffi::c_str_to_bytes;
-    String::from_utf8_lossy(c_str_to_bytes(&c_str)).into_owned()
+    String::from_utf8_lossy(CStr::from_ptr(c_str).to_bytes()).into_owned()
 }
 
 /// Replacement for `ToCStr::with_c_str`
 pub fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const c_char) -> T {
-    let c_str = CString::from_slice(s.as_bytes());
-    f(c_str.as_slice_with_nul().as_ptr())
+    let c_str = CString::new(s.as_bytes());
+    f(c_str.unwrap().as_bytes_with_nul().as_ptr() as *const _)
 }
 
 /// Wrapper for `glfwGetVersionString`.
@@ -794,7 +795,7 @@ impl Monitor {
         unsafe {
             let mut count = 0;
             let ptr = ffi::glfwGetVideoModes(self.ptr, &mut count);
-            slice::from_raw_buf(&ptr, count as usize).iter().map(VidMode::from_glfw_vid_mode).collect()
+            slice::from_raw_parts(ptr, count as usize).iter().map(VidMode::from_glfw_vid_mode).collect()
         }
     }
 
@@ -815,11 +816,11 @@ impl Monitor {
         unsafe {
             let llramp = *ffi::glfwGetGammaRamp(self.ptr);
             GammaRamp {
-                red:    slice::from_raw_buf(&(llramp.red as *const c_ushort), llramp.size as usize)
+                red:    slice::from_raw_parts(llramp.red as *const c_ushort, llramp.size as usize)
                               .iter().map(|&x| x).collect(),
-                green:  slice::from_raw_buf(&(llramp.green as *const c_ushort), llramp.size as usize)
+                green:  slice::from_raw_parts(llramp.green as *const c_ushort, llramp.size as usize)
                               .iter().map(|&x| x).collect(),
-                blue:   slice::from_raw_buf(&(llramp.blue as *const c_ushort), llramp.size as usize)
+                blue:   slice::from_raw_parts(llramp.blue as *const c_ushort, llramp.size as usize)
                               .iter().map(|&x| x).collect(),
             }
         }
@@ -1099,7 +1100,7 @@ pub fn flush_messages<'a, Message: Send>(receiver: &'a Receiver<Message>) -> Flu
 /// `Receiver`'s queue.
 pub struct FlushedMessages<'a, Message: 'a>(&'a Receiver<Message>);
 
-impl<'a, Message: Send> Iterator for FlushedMessages<'a, Message> {
+impl<'a, Message: 'static + Send> Iterator for FlushedMessages<'a, Message> {
     type Item = Message;
 
     fn next(&mut self) -> Option<Message> {
@@ -1649,7 +1650,7 @@ impl Joystick {
         unsafe {
             let mut count = 0;
             let ptr = ffi::glfwGetJoystickAxes(self.id as c_int, &mut count);
-            slice::from_raw_buf(&ptr, count as usize).iter().map(|&a| a as f32).collect()
+            slice::from_raw_parts(ptr, count as usize).iter().map(|&a| a as f32).collect()
         }
     }
 
@@ -1658,7 +1659,7 @@ impl Joystick {
         unsafe {
             let mut count = 0;
             let ptr = ffi::glfwGetJoystickButtons(self.id as c_int, &mut count);
-            slice::from_raw_buf(&ptr, count as usize).iter().map(|&b| b as c_int).collect()
+            slice::from_raw_parts(ptr, count as usize).iter().map(|&b| b as c_int).collect()
         }
     }
 


Test patch: