-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #832 from neon-bindings/kv/copy-safety
Copy safety
- Loading branch information
Showing
16 changed files
with
386 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
use std::fmt::Debug; | ||
use std::mem; | ||
|
||
use crate::types::Value; | ||
|
||
pub trait SuperType<T: Value> { | ||
fn upcast_internal(v: T) -> Self; | ||
fn upcast_internal(v: &T) -> Self; | ||
} | ||
|
||
#[doc(hidden)] | ||
/// Trait asserting that `Self` is a transparent wrapper around `Self::Inner` | ||
/// with identical representation and may be safely transmuted. | ||
/// | ||
/// # Safety | ||
/// `Self` must be `#[repr(transparent)]` with a field `Self::Inner` | ||
pub unsafe trait TransparentNoCopyWrapper: Sized { | ||
type Inner: Debug + Copy; | ||
|
||
// A default implementation cannot be provided because it would create | ||
// dependently sized types. This may be supported in a future Rust version. | ||
fn into_inner(self) -> Self::Inner; | ||
|
||
fn wrap_ref(s: &Self::Inner) -> &Self { | ||
unsafe { mem::transmute(s) } | ||
} | ||
|
||
fn wrap_mut(s: &mut Self::Inner) -> &mut Self { | ||
unsafe { mem::transmute(s) } | ||
} | ||
} |
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
Oops, something went wrong.