-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper traits to handle deref & borrow and auto-derive common traits
- Loading branch information
1 parent
6da9645
commit 8622292
Showing
20 changed files
with
113 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod std; | ||
|
||
pub use galvan_transpiler::galvan_module; | ||
|
||
#[cfg(feature = "build")] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::borrow::{Borrow, BorrowMut}; | ||
use std::ops::Deref; | ||
use std::sync::{Arc, Mutex, MutexGuard}; | ||
|
||
pub trait __ToRef { | ||
type Inner; | ||
fn __to_ref(&self) -> Arc<Mutex<Self::Inner>>; | ||
} | ||
|
||
impl<T: ToOwned> __ToRef for &T { | ||
type Inner = T::Owned; | ||
|
||
#[inline(always)] | ||
fn __to_ref(&self) -> Arc<Mutex<Self::Inner>> { | ||
Arc::new(Mutex::new(self.deref().to_owned())) | ||
} | ||
} | ||
|
||
impl<T> __ToRef for Arc<Mutex<T>> { | ||
type Inner = T; | ||
|
||
#[inline(always)] | ||
fn __to_ref(&self) -> Arc<Mutex<Self::Inner>> { | ||
Arc::clone(self) | ||
} | ||
} | ||
|
||
pub trait __Borrow<'a> { | ||
type Inner; | ||
fn __borrow(&'a self) -> Self::Inner; | ||
} | ||
|
||
impl<'a, T: Borrow<T>> __Borrow<'a> for &'a T { | ||
type Inner = &'a T; | ||
#[inline(always)] | ||
fn __borrow(&'a self) -> Self::Inner { | ||
(**self).borrow() | ||
} | ||
} | ||
|
||
impl<'a, T: 'a> __Borrow<'a> for Arc<Mutex<T>> { | ||
type Inner = MutexGuard<'a, T>; | ||
#[inline(always)] | ||
fn __borrow(&'a self) -> Self::Inner { | ||
self.lock().unwrap() | ||
} | ||
} | ||
|
||
impl<'a, T: 'a> __Borrow<'a> for MutexGuard<'a, T> { | ||
type Inner = &'a T; | ||
#[inline(always)] | ||
fn __borrow(&'a self) -> Self::Inner { | ||
(*self).deref() | ||
} | ||
} | ||
|
||
pub trait __Mut<'a> { | ||
type Inner; | ||
|
||
fn __mut(&'a mut self) -> Self::Inner; | ||
} | ||
|
||
impl<'a, T: BorrowMut<T> + 'a> __Mut<'a> for T { | ||
type Inner = &'a mut T; | ||
|
||
fn __mut(&'a mut self) -> Self::Inner { | ||
self.borrow_mut() | ||
} | ||
} |