From 98596554b3d88a7619bdbc3ac7462a95b7263e96 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 14 Jul 2017 18:54:54 -0500 Subject: split macro parser into its own crate and improve error handling / reporting --- src/lib.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 23f3abd..daca2d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,6 +82,14 @@ impl

Peripheral

{ Peripheral { peripheral } } + #[inline(always)] + pub unsafe fn borrow<'cs>( + &'static self, + _cs: &'cs CriticalSection, + ) -> &'cs P { + &*self.peripheral.get() + } + #[inline(always)] pub unsafe fn claim( &'static self, @@ -123,7 +131,25 @@ pub struct Resource { impl Resource { pub const fn new(value: T) -> Self { - Resource { data: UnsafeCell::new(value) } + Resource { + data: UnsafeCell::new(value), + } + } + + #[inline(always)] + pub unsafe fn borrow<'cs>( + &'static self, + _cs: &'cs CriticalSection, + ) -> &'cs Static { + Static::ref_(&*self.data.get()) + } + + #[inline(always)] + pub unsafe fn borrow_mut<'cs>( + &'static self, + _cs: &'cs CriticalSection, + ) -> &'cs mut Static { + Static::ref_mut(&mut *self.data.get()) } #[inline(always)] -- cgit v1.2.3