Draft interfaces
This commit is contained in:
commit
42349a315e
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[registries]
|
||||||
|
landgrafhomyak = { index = "sparse+https://cargo.landgrafhomyak.ru/" }
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/.idea/
|
||||||
|
Cargo.lock
|
||||||
|
target/
|
||||||
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "dynamic-memory-api-0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
rust = { nonstandard_style = "allow" }
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
[patch.landgrafhomyak]
|
||||||
5
src/dyn.rs
Normal file
5
src/dyn.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub unsafe trait Dyn<T: Sized>: Drop + Sized {
|
||||||
|
fn getRef<'s>(&'s self) -> &'s mut T;
|
||||||
|
fn free<'s>(&'s mut self);
|
||||||
|
}
|
||||||
|
|
||||||
27
src/general.rs
Normal file
27
src/general.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
|
pub unsafe trait GeneralPurposeHeap {
|
||||||
|
type Dyn<T: Sized>: crate::Dyn<T>;
|
||||||
|
|
||||||
|
fn alloc<'s, T: Sized>(&'s mut self, value: T) -> Self::Dyn<T> {
|
||||||
|
return self
|
||||||
|
.tryAlloc(value)
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allocUninitialized<'s, T: Sized>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||||
|
return self
|
||||||
|
.tryAllocUninitialized()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allocZeroed<'s, T: Sized>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||||
|
return self
|
||||||
|
.tryAllocZeroed()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tryAlloc<'s, T: Sized>(&'s mut self, value: T) -> Option<Self::Dyn<T>>;
|
||||||
|
fn tryAllocUninitialized<'s, T: Sized>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||||
|
fn tryAllocZeroed<'s, T: Sized>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||||
|
}
|
||||||
12
src/lib.rs
Normal file
12
src/lib.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
mod r#dyn;
|
||||||
|
mod general;
|
||||||
|
mod pages;
|
||||||
|
mod stack;
|
||||||
|
mod typed;
|
||||||
|
|
||||||
|
pub use pages::Page;
|
||||||
|
pub use pages::PagesManager;
|
||||||
|
pub use r#dyn::Dyn;
|
||||||
|
pub use stack::StackHeap;
|
||||||
|
pub use typed::TypedHeap;
|
||||||
|
pub use general::GeneralPurposeHeap;
|
||||||
27
src/pages.rs
Normal file
27
src/pages.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
enum ExtensionResult {
|
||||||
|
OK,
|
||||||
|
NO_MEMORY,
|
||||||
|
EXTENSION_BUSY,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe trait Page {
|
||||||
|
fn getMemory(&self) -> NonNull<[u8]>;
|
||||||
|
|
||||||
|
fn releasePage(self);
|
||||||
|
|
||||||
|
fn tryExtend(&mut self, minimalAdditionalSize: usize) -> ExtensionResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe trait PagesManager {
|
||||||
|
type Page: Page;
|
||||||
|
|
||||||
|
fn offerPage<'s>(&'s mut self, minsize: usize) -> &'s Self::Page {
|
||||||
|
return self
|
||||||
|
.tryOfferPage(minsize)
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tryOfferPage<'s>(&'s mut self, minimalSize: usize) -> Option<&'s Self::Page>;
|
||||||
|
}
|
||||||
25
src/stack.rs
Normal file
25
src/stack.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
|
pub unsafe trait StackHeap {
|
||||||
|
fn childScope<'s>(&'s mut self) -> impl StackHeap;
|
||||||
|
|
||||||
|
fn alloc<'s, T: Sized>(&'s mut self, value: T) -> &'s mut T {
|
||||||
|
return self
|
||||||
|
.tryAlloc(value)
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
fn allocUninitialized<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||||
|
return self
|
||||||
|
.tryAllocUninitialized()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
fn allocZeroed<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||||
|
return self
|
||||||
|
.tryAllocZeroed()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tryAlloc<'s, T: Sized>(&'s mut self, value: T) -> Option<&'s mut T>;
|
||||||
|
fn tryAllocUninitialized<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||||
|
fn tryAllocZeroed<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||||
|
}
|
||||||
28
src/typed.rs
Normal file
28
src/typed.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
|
pub unsafe trait TypedHeap<T: Sized> {
|
||||||
|
type Dyn<_T: Sized>: crate::Dyn<_T>;
|
||||||
|
|
||||||
|
fn alloc<'s>(&'s mut self, value: T) -> Self::Dyn<T> {
|
||||||
|
return self
|
||||||
|
.tryAlloc(value)
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allocUninitialized<'s>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||||
|
return self
|
||||||
|
.tryAllocUninitialized()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allocZeroed<'s>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||||
|
return self
|
||||||
|
.tryAllocZeroed()
|
||||||
|
.unwrap_or_else(|| panic!("Out of memory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tryAlloc<'s>(&'s mut self, value: T) -> Option<Self::Dyn<T>>;
|
||||||
|
fn tryAllocUninitialized<'s>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||||
|
fn tryAllocZeroed<'s>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user