From d97db0936c546c61454e5163ed5eeb57b24ff78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Asensio=20Garc=C3=ADa?= Date: Sun, 8 Jan 2023 16:19:26 +0100 Subject: [PATCH 1/3] Modify lifetimes in buffer and buffer_mut methods --- api/src/info.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/info.rs b/api/src/info.rs index 248362ab..8df26ebb 100644 --- a/api/src/info.rs +++ b/api/src/info.rs @@ -177,12 +177,12 @@ impl FrameBuffer { } /// Returns the raw bytes of the framebuffer as slice. - pub fn buffer(&self) -> &[u8] { + pub fn buffer<'a>(&self) -> &'a [u8] { unsafe { self.create_buffer() } } /// Returns the raw bytes of the framebuffer as mutable slice. - pub fn buffer_mut(&mut self) -> &mut [u8] { + pub fn buffer_mut<'a>(&mut self) -> &'a mut [u8] { unsafe { self.create_buffer_mut() } } From e49d58b63bd9bc9f5179909402a65c883a90cc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Asensio=20Garc=C3=ADa?= Date: Sun, 8 Jan 2023 17:30:51 +0100 Subject: [PATCH 2/3] Fix an issue of ownership --- api/src/info.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/src/info.rs b/api/src/info.rs index 8df26ebb..dcf922ca 100644 --- a/api/src/info.rs +++ b/api/src/info.rs @@ -177,12 +177,17 @@ impl FrameBuffer { } /// Returns the raw bytes of the framebuffer as slice. - pub fn buffer<'a>(&self) -> &'a [u8] { + pub fn buffer(&self) -> &[u8] { unsafe { self.create_buffer() } } /// Returns the raw bytes of the framebuffer as mutable slice. - pub fn buffer_mut<'a>(&mut self) -> &'a mut [u8] { + pub fn buffer_mut(&mut self) -> &mut [u8] { + unsafe { self.create_buffer_mut() } + } + + /// The same as buffer_mut() but takes the ownership and returns the mutable buffer as static. So it's not possible to calling it twice. + pub fn into_buffer(self) -> &'static mut [u8] { unsafe { self.create_buffer_mut() } } From dfb5f1e9847a100402df8d36c9bc6dd7ed837fdc Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 9 Jan 2023 17:39:42 +0100 Subject: [PATCH 3/3] Improve docs --- api/src/info.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/info.rs b/api/src/info.rs index dcf922ca..38a58fff 100644 --- a/api/src/info.rs +++ b/api/src/info.rs @@ -186,7 +186,10 @@ impl FrameBuffer { unsafe { self.create_buffer_mut() } } - /// The same as buffer_mut() but takes the ownership and returns the mutable buffer as static. So it's not possible to calling it twice. + /// Converts the frame buffer to a raw byte slice. + /// + /// The same as `buffer_mut()` but takes the ownership and returns the + /// mutable buffer with a `'static` lifetime. pub fn into_buffer(self) -> &'static mut [u8] { unsafe { self.create_buffer_mut() } }