mirror of
https://github.com/Noratrieb/stuff.git
synced 2026-01-14 16:35:08 +01:00
add backend
This commit is contained in:
parent
d144819eb0
commit
6963591f4f
1 changed files with 33 additions and 0 deletions
33
src/backend.rs
Normal file
33
src/backend.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use sptr::Strict;
|
||||
|
||||
pub trait Backend<T> {
|
||||
type Stored: Copy;
|
||||
|
||||
fn get_ptr(s: Self::Stored) -> (*mut T, Self);
|
||||
|
||||
fn set_ptr(provenance: *mut T, addr: Self) -> Self::Stored;
|
||||
|
||||
fn get_int(s: Self::Stored) -> Self;
|
||||
|
||||
fn set_int(s: Self::Stored, int: Self) -> Self::Stored;
|
||||
}
|
||||
|
||||
impl<T> Backend<T> for usize {
|
||||
type Stored = *mut T;
|
||||
|
||||
fn get_ptr(s: Self::Stored) -> (*mut T, Self) {
|
||||
(s, Strict::addr(s))
|
||||
}
|
||||
|
||||
fn set_ptr(provenance: *mut T, addr: Self) -> Self::Stored {
|
||||
Strict::with_addr(provenance, addr)
|
||||
}
|
||||
|
||||
fn get_int(s: Self::Stored) -> Self {
|
||||
Strict::addr(s)
|
||||
}
|
||||
|
||||
fn set_int(s: Self::Stored, int: Self) -> Self::Stored {
|
||||
Strict::with_addr(s, int)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue