Skip to content

Commit 5b1845e

Browse files
committed
Use lifetimes better
1 parent 3de0ce7 commit 5b1845e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/base.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ pub struct StructPtr<'a, T: 'a> {
8888
phantom: PhantomData<&'a T>
8989
}
9090

91+
impl<'a, T: 'a> Copy for StructPtr<'a, T> {}
92+
impl<'a, T: 'a> Clone for StructPtr<'a, T> {
93+
fn clone(&self) -> Self {
94+
*self
95+
}
96+
}
97+
98+
impl<'a, T: 'a> StructPtr<'a, T> {
99+
pub unsafe fn borrow(self) -> &'a T {
100+
&*self.ptr
101+
}
102+
}
103+
91104

92105
/// `Event` wraps a pointer to `xcb_*_event_t`
93106
/// this pointer will be freed when the `Event` goes out of scope
@@ -229,6 +242,11 @@ impl<T> Drop for Reply<T> {
229242
}
230243
}
231244

245+
impl<T> Reply<T> {
246+
pub unsafe fn borrow<'a>(&'a self) -> &'a T {
247+
&*self.ptr
248+
}
249+
}
232250
#[cfg(feature="thread")]
233251
unsafe impl<T> Send for Reply<T> {}
234252
#[cfg(feature="thread")]

0 commit comments

Comments
 (0)