mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-19 13:36:54 +02:00
docs
This commit is contained in:
parent
f0158ee8ae
commit
7c561d544d
1 changed files with 3 additions and 0 deletions
|
@ -9,11 +9,13 @@
|
|||
use std::any::TypeId;
|
||||
use std::mem::size_of;
|
||||
|
||||
/// Returns true if two types are in fact the same type.
|
||||
#[inline(always)]
|
||||
pub fn same_type<U: 'static, V: 'static>() -> bool {
|
||||
TypeId::of::<U>() == TypeId::of::<V>() && size_of::<U>() == size_of::<V>()
|
||||
}
|
||||
|
||||
/// Cast a reference if the types are equal, such as from a specific type to a generic that it implements.
|
||||
#[inline(always)]
|
||||
pub fn cast_ref<U: 'static, V: 'static>(u: &U) -> Option<&V> {
|
||||
if same_type::<U, V>() {
|
||||
|
@ -23,6 +25,7 @@ pub fn cast_ref<U: 'static, V: 'static>(u: &U) -> Option<&V> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Cast a reference if the types are equal, such as from a specific type to a generic that it implements.
|
||||
#[inline(always)]
|
||||
pub fn cast_mut<U: 'static, V: 'static>(u: &mut U) -> Option<&mut V> {
|
||||
if same_type::<U, V>() {
|
||||
|
|
Loading…
Add table
Reference in a new issue