-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25ff9f4
commit 8f898a1
Showing
3 changed files
with
37 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "kaminari" | ||
version = "0.4.0" | ||
version = "0.4.1" | ||
edition = "2021" | ||
authors = ["zephyr <[email protected]>"] | ||
keywords = ["lightws", "network"] | ||
|
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 |
---|---|---|
|
@@ -30,3 +30,4 @@ pub mod nop; | |
pub mod tls; | ||
pub mod mix; | ||
pub mod opt; | ||
pub mod trick; |
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,35 @@ | ||
use core::ops::Deref; | ||
|
||
// Safety: | ||
// pointer is not null once inited(comes from an immutable ref) | ||
// pointee memory is always valid during the eventloop | ||
pub struct Ref<T>(*const T); | ||
|
||
unsafe impl<T: Send + Sync> Send for Ref<T> {} | ||
unsafe impl<T: Send + Sync> Sync for Ref<T> {} | ||
|
||
impl<T> Copy for Ref<T> {} | ||
|
||
impl<T> Clone for Ref<T> { | ||
fn clone(&self) -> Self { *self } | ||
} | ||
|
||
impl<T> Deref for Ref<T> { | ||
type Target = T; | ||
|
||
#[inline] | ||
fn deref(&self) -> &Self::Target { unsafe { &*self.0 } } | ||
} | ||
|
||
impl<T> AsRef<T> for Ref<T> { | ||
#[inline] | ||
fn as_ref(&self) -> &T { unsafe { &*self.0 } } | ||
} | ||
|
||
impl<T> From<&T> for Ref<T> { | ||
fn from(x: &T) -> Self { Ref(x as *const _) } | ||
} | ||
|
||
impl<T> Ref<T> { | ||
pub const fn new(x: &T) -> Self { Self(x as *const _) } | ||
} |