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"
|
name = "tinyptr"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyptr-alloc"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"tinyptr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
|
12
Cargo.nix
12
Cargo.nix
|
@ -5,6 +5,7 @@ args@{
|
||||||
release ? true,
|
release ? true,
|
||||||
rootFeatures ? [
|
rootFeatures ? [
|
||||||
"tinyptr/default"
|
"tinyptr/default"
|
||||||
|
"tinyptr-alloc/default"
|
||||||
"rkbfirm/default"
|
"rkbfirm/default"
|
||||||
],
|
],
|
||||||
rustPackages,
|
rustPackages,
|
||||||
|
@ -43,6 +44,7 @@ in
|
||||||
cargo2nixVersion = "0.11.0";
|
cargo2nixVersion = "0.11.0";
|
||||||
workspace = {
|
workspace = {
|
||||||
tinyptr = rustPackages.unknown.tinyptr."0.1.0";
|
tinyptr = rustPackages.unknown.tinyptr."0.1.0";
|
||||||
|
tinyptr-alloc = rustPackages.unknown.tinyptr-alloc."0.1.0";
|
||||||
rkbfirm = rustPackages.unknown.rkbfirm."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 {
|
"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");
|
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 {
|
"registry+https://github.com/rust-lang/crates.io-index".unicode-ident."1.0.1" = overridableMkRustCrate (profileName: rec {
|
||||||
name = "unicode-ident";
|
name = "unicode-ident";
|
||||||
version = "1.0.1";
|
version = "1.0.1";
|
||||||
|
|
|
@ -5,7 +5,8 @@ edition = "2021"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"lib/tinyptr"
|
"lib/tinyptr",
|
||||||
|
"lib/tinyptr-alloc"
|
||||||
]
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
49
flake.nix
49
flake.nix
|
@ -19,8 +19,15 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, rust-overlay, cargo2nix, ... } @ inputs: flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
outputs = {
|
||||||
let
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
flake-utils,
|
||||||
|
rust-overlay,
|
||||||
|
cargo2nix,
|
||||||
|
...
|
||||||
|
} @ inputs:
|
||||||
|
flake-utils.lib.eachSystem ["x86_64-linux"] (system: let
|
||||||
overlays = [
|
overlays = [
|
||||||
cargo2nix.overlays.default
|
cargo2nix.overlays.default
|
||||||
(import rust-overlay)
|
(import rust-overlay)
|
||||||
|
@ -35,27 +42,27 @@
|
||||||
target = "thumbv6m-none-eabi";
|
target = "thumbv6m-none-eabi";
|
||||||
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all;
|
||||||
};
|
};
|
||||||
in
|
in rec {
|
||||||
rec {
|
devShells.default = with pkgs;
|
||||||
devShells.default = with pkgs; mkShell {
|
mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(rust-bin.nightly.latest.default.override {
|
(rust-bin.nightly.latest.default.override {
|
||||||
extensions = [ "rust-src" ];
|
extensions = ["rust-src"];
|
||||||
targets = ["thumbv6m-none-eabi"];
|
targets = ["thumbv6m-none-eabi"];
|
||||||
})
|
})
|
||||||
cargo2nix.packages.${system}.cargo2nix
|
cargo2nix.packages.${system}.cargo2nix
|
||||||
elf2uf2-rs
|
elf2uf2-rs
|
||||||
cargo-embed
|
cargo-embed
|
||||||
llvmPackages_latest.bintools
|
llvmPackages_latest.bintools
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
packages = rec {
|
packages = rec {
|
||||||
rkbfirm-source = pkgs.releaseTools.sourceTarball {
|
rkbfirm-source = pkgs.releaseTools.sourceTarball {
|
||||||
name = "rkbfirm-source";
|
name = "rkbfirm-source";
|
||||||
src = self;
|
src = self;
|
||||||
officialRelease = true;
|
officialRelease = true;
|
||||||
version = self.lastModifiedDate;
|
version = self.lastModifiedDate;
|
||||||
nativeBuildInputs = [ pkgs.zstd ];
|
nativeBuildInputs = [pkgs.zstd];
|
||||||
distPhase = ''
|
distPhase = ''
|
||||||
releaseName=rkb1-src-$version
|
releaseName=rkb1-src-$version
|
||||||
mkdir -p $out/tarballs
|
mkdir -p $out/tarballs
|
||||||
|
@ -64,9 +71,11 @@
|
||||||
(cd .. && tar -cf- $releaseName | zstd --ultra -22 > $out/tarballs/$releaseName.tar.zst) || false
|
(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";
|
configureCargo = "true";
|
||||||
});
|
});
|
||||||
|
tinyptr-crate = rustPkgs.workspace.tinyptr {};
|
||||||
|
tinyptr-alloc-crate = rustPkgs.workspace.tinyptr-alloc {};
|
||||||
rkbfirm = pkgs.stdenvNoCC.mkDerivation {
|
rkbfirm = pkgs.stdenvNoCC.mkDerivation {
|
||||||
pname = "rkbfirm";
|
pname = "rkbfirm";
|
||||||
src = self;
|
src = self;
|
||||||
|
@ -93,10 +102,12 @@
|
||||||
};
|
};
|
||||||
default = rkbfirm;
|
default = rkbfirm;
|
||||||
devShell = devShells.default;
|
devShell = devShells.default;
|
||||||
|
inherit formatter;
|
||||||
};
|
};
|
||||||
nixosModules.default = import ./nixos {
|
nixosModules.default = import ./nixos {
|
||||||
inherit inputs system;
|
inherit inputs system;
|
||||||
};
|
};
|
||||||
hydraJobs = packages;
|
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;
|
use core::hash::Hash;
|
||||||
|
|
||||||
pub mod ptr;
|
pub mod ptr;
|
||||||
|
mod tiny_ref;
|
||||||
|
pub use tiny_ref::*;
|
||||||
|
|
||||||
/// Trait that defines valid destination types for a pointer.
|
/// Trait that defines valid destination types for a pointer.
|
||||||
pub trait Pointable {
|
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