add tinyptr-alloc
This commit is contained in:
parent
b57c14d346
commit
9747d94ccc
9 changed files with 105 additions and 20 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -569,6 +569,13 @@ dependencies = [
|
|||
name = "tinyptr"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "tinyptr-alloc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tinyptr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.1"
|
||||
|
|
12
Cargo.nix
12
Cargo.nix
|
@ -5,6 +5,7 @@ args@{
|
|||
release ? true,
|
||||
rootFeatures ? [
|
||||
"tinyptr/default"
|
||||
"tinyptr-alloc/default"
|
||||
"rkbfirm/default"
|
||||
],
|
||||
rustPackages,
|
||||
|
@ -43,6 +44,7 @@ in
|
|||
cargo2nixVersion = "0.11.0";
|
||||
workspace = {
|
||||
tinyptr = rustPackages.unknown.tinyptr."0.1.0";
|
||||
tinyptr-alloc = rustPackages.unknown.tinyptr-alloc."0.1.0";
|
||||
rkbfirm = rustPackages.unknown.rkbfirm."0.1.0";
|
||||
};
|
||||
"registry+https://github.com/rust-lang/crates.io-index".aho-corasick."0.7.18" = overridableMkRustCrate (profileName: rec {
|
||||
|
@ -810,6 +812,16 @@ in
|
|||
src = fetchCrateLocal (workspaceSrc + "/lib/tinyptr");
|
||||
});
|
||||
|
||||
"unknown".tinyptr-alloc."0.1.0" = overridableMkRustCrate (profileName: rec {
|
||||
name = "tinyptr-alloc";
|
||||
version = "0.1.0";
|
||||
registry = "unknown";
|
||||
src = fetchCrateLocal (workspaceSrc + "/lib/tinyptr-alloc");
|
||||
dependencies = {
|
||||
tinyptr = rustPackages."unknown".tinyptr."0.1.0" { inherit profileName; };
|
||||
};
|
||||
});
|
||||
|
||||
"registry+https://github.com/rust-lang/crates.io-index".unicode-ident."1.0.1" = overridableMkRustCrate (profileName: rec {
|
||||
name = "unicode-ident";
|
||||
version = "1.0.1";
|
||||
|
|
|
@ -5,7 +5,8 @@ edition = "2021"
|
|||
|
||||
[workspace]
|
||||
members = [
|
||||
"lib/tinyptr"
|
||||
"lib/tinyptr",
|
||||
"lib/tinyptr-alloc"
|
||||
]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
27
flake.nix
27
flake.nix
|
@ -19,8 +19,15 @@
|
|||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, cargo2nix, ... } @ inputs: flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
||||
let
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
rust-overlay,
|
||||
cargo2nix,
|
||||
...
|
||||
} @ inputs:
|
||||
flake-utils.lib.eachSystem ["x86_64-linux"] (system: let
|
||||
overlays = [
|
||||
cargo2nix.overlays.default
|
||||
(import rust-overlay)
|
||||
|
@ -35,12 +42,12 @@
|
|||
target = "thumbv6m-none-eabi";
|
||||
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
||||
};
|
||||
in
|
||||
rec {
|
||||
devShells.default = with pkgs; mkShell {
|
||||
in rec {
|
||||
devShells.default = with pkgs;
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
(rust-bin.nightly.latest.default.override {
|
||||
extensions = [ "rust-src" ];
|
||||
extensions = ["rust-src"];
|
||||
targets = ["thumbv6m-none-eabi"];
|
||||
})
|
||||
cargo2nix.packages.${system}.cargo2nix
|
||||
|
@ -55,7 +62,7 @@
|
|||
src = self;
|
||||
officialRelease = true;
|
||||
version = self.lastModifiedDate;
|
||||
nativeBuildInputs = [ pkgs.zstd ];
|
||||
nativeBuildInputs = [pkgs.zstd];
|
||||
distPhase = ''
|
||||
releaseName=rkb1-src-$version
|
||||
mkdir -p $out/tarballs
|
||||
|
@ -64,9 +71,11 @@
|
|||
(cd .. && tar -cf- $releaseName | zstd --ultra -22 > $out/tarballs/$releaseName.tar.zst) || false
|
||||
'';
|
||||
};
|
||||
rkbfirm-crate = (rustPkgs.workspace.rkbfirm { }).overrideAttrs(old: {
|
||||
rkbfirm-crate = (rustPkgs.workspace.rkbfirm {}).overrideAttrs (old: {
|
||||
configureCargo = "true";
|
||||
});
|
||||
tinyptr-crate = rustPkgs.workspace.tinyptr {};
|
||||
tinyptr-alloc-crate = rustPkgs.workspace.tinyptr-alloc {};
|
||||
rkbfirm = pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "rkbfirm";
|
||||
src = self;
|
||||
|
@ -93,10 +102,12 @@
|
|||
};
|
||||
default = rkbfirm;
|
||||
devShell = devShells.default;
|
||||
inherit formatter;
|
||||
};
|
||||
nixosModules.default = import ./nixos {
|
||||
inherit inputs system;
|
||||
};
|
||||
hydraJobs = packages;
|
||||
formatter = pkgs.alejandra;
|
||||
});
|
||||
}
|
||||
|
|
9
lib/tinyptr-alloc/Cargo.toml
Normal file
9
lib/tinyptr-alloc/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "tinyptr-alloc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tinyptr = { path = "../tinyptr" }
|
10
lib/tinyptr-alloc/src/lib.rs
Normal file
10
lib/tinyptr-alloc/src/lib.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#![no_std]
|
||||
|
||||
use tinyptr::ptr::MutPtr;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ListNode<const BASE: usize> {
|
||||
pub next: MutPtr<Self, BASE>,
|
||||
pub size: u16
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@
|
|||
use core::hash::Hash;
|
||||
|
||||
pub mod ptr;
|
||||
mod tiny_ref;
|
||||
pub use tiny_ref::*;
|
||||
|
||||
/// Trait that defines valid destination types for a pointer.
|
||||
pub trait Pointable {
|
||||
|
|
31
lib/tinyptr/src/tiny_ref/const_ref.rs
Normal file
31
lib/tinyptr/src/tiny_ref/const_ref.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use core::{marker::PhantomData, ops::Deref, borrow::Borrow};
|
||||
|
||||
use crate::{Pointable, ptr::NonNull};
|
||||
|
||||
/// Constant Tiny Reference
|
||||
#[repr(transparent)]
|
||||
pub struct Ref<'a, T: Pointable + ?Sized, const BASE: usize> {
|
||||
pub(crate) ptr: NonNull<T, BASE>,
|
||||
pub(crate) _marker: PhantomData<&'a T>
|
||||
}
|
||||
|
||||
impl<T: Pointable + ?Sized, const BASE: usize> Copy for Ref<'_, T, BASE> {}
|
||||
impl<T: Pointable + ?Sized, const BASE: usize> Clone for Ref<'_, T, BASE> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
impl<T: Pointable + ?Sized, const BASE: usize> Deref for Ref<'_, T, BASE> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
// SAFETY: Reference must be valid to be constructed
|
||||
unsafe {
|
||||
&*(*self).ptr.as_ptr().wide()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Pointable + ?Sized, const BASE: usize> Borrow<T> for Ref<'_, T, BASE> {
|
||||
fn borrow(&self) -> &T {
|
||||
&*self
|
||||
}
|
||||
}
|
2
lib/tinyptr/src/tiny_ref/mod.rs
Normal file
2
lib/tinyptr/src/tiny_ref/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
mod const_ref;
|
||||
pub use const_ref::*;
|
Loading…
Reference in a new issue