Skip to content

Instantly share code, notes, and snippets.

View Nadrieril's full-sized avatar

Nadrieril Nadrieril

  • Inria
  • Paris, France
  • 08:03 (UTC +01:00)
  • X @nadrieril
View GitHub Profile
@Nadrieril
Nadrieril / patterns.rs
Created December 5, 2024 10:20
Lesser-known rust pattern-matching features
// Destructuring assignment
fn fibonacci(n: u64) -> u64 {
let mut a = 1;
let mut b = 1;
for _ in 0..n {
(a, b) = (a + b, a);
}
b
}
@Nadrieril
Nadrieril / buffer_allocator.rs
Last active August 14, 2024 21:34
`&mut [u8]` as `Allocator`
#![feature(allocator_api)]
#![feature(slice_ptr_get)]
#![feature(strict_provenance)]
use core::{alloc::Layout, ptr::NonNull, sync::atomic::AtomicUsize};
use std::alloc::{AllocError, Allocator};
use std::marker::PhantomData;
/// Allocator backed by a provided buffer. Once the buffer is full, all subsequent allocations fail.
pub struct BufferAllocator<'a> {
/// The backing buffer.
@Nadrieril
Nadrieril / iterator_visitor.rs
Last active June 15, 2024 15:29
This is a sketch written for https://github.com/nikis05/derive-visitor/issues/13 of a visitor interface that is polled externally
// I wrote https://github.com/Nadrieril/type-walker to replace this
@Nadrieril
Nadrieril / arbitrary_self_types.rs
Created November 23, 2023 22:35
Test the method selection algorithm of `arbitrary_self_types`
#![feature(arbitrary_self_types)]
#![allow(dead_code)]
macro_rules! assert_priority {
(prefer method on $expected:ident given: $($rest:tt)*) => {
{
// Define one wrapper per entry, with any `foo` methods specified.
assert_priority!(@define_ptrs, $($rest)*);
// This is the `P<Q<...>>` type we want to play with.
type Combined = assert_priority!(@combined_type, $($rest)*);
@Nadrieril
Nadrieril / x.sh
Last active January 8, 2021 19:59
My `x.py` for rustc development
#!/usr/bin/env bash
# Wrapper around `x.py`. Assumes it's being run from the root of the rustc repo.
RUSTC_REPO="$(realpath "$PWD")"
RUSTC_PERF_REPO="$RUSTC_REPO/../rustc-perf"
X_PY="$RUSTC_REPO/x.py"
RUSTC="$RUSTC_REPO/build/x86_64-unknown-linux-gnu/stage1/bin/rustc"
RUSTFMT="$RUSTC_REPO/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"
cd $RUSTC_REPO || exit
@Nadrieril
Nadrieril / shell.nix
Last active October 19, 2024 15:23
Building LineageOS on NixOS
# I used this shell.nix to build LineageOS 13.0 for my maguro (Samsung Galaxy Nexus GSM) phone
# The build instructions for normal Linuxes are here: https://wiki.lineageos.org/devices/maguro/build
# For NixOS, follow those instructions but skip anything related to installing packages
# Detailed instructions:
# cd into an empty directory of your choice
# copy this file there
# in nix-shell:
# $ repo init -u https://github.com/LineageOS/android.git -b cm-13.0
# $ repo sync
# $ source build/envsetup.sh