Skip to content

Instantly share code, notes, and snippets.

View Centril's full-sized avatar
🏠
Working from home

Mazdak Farrokhzad Centril

🏠
Working from home
  • Sweden
View GitHub Profile
@Centril
Centril / error-index.md
Created November 2, 2018 00:28
src/error-index.md

Error Index

E0001

This error occurs when #[derive(Arbitrary)] is used on a type which has any lifetime parameters. For example:

@Centril
Centril / good_bad_list.md
Last active August 9, 2018 06:29
Type ascription inference good/bad list

Given the following type definitions:

struct Foo(usize);

struct Wrapping<T>(T);

struct Product<A, B>(A, B);

trait Trait { type Assoc; }
@Centril
Centril / for_else.rs
Created June 17, 2018 01:14
for/while/while let .. else
// while P { B_1 } else { B_2 } */
// ==>
/*
if P {
B_1;
while P {
B_1
}
@Centril
Centril / unnamed-structs.md
Created May 5, 2018 20:22
Unnamed structs

Unnamed structs

Nominal type equivalence

Let ≡n be the equivalence class of nominally equivalent types. A ≡n B denotes that A and B are nominally the same type.

{ foo: T, bar: U }n { bar: U, foo: T } // Order does not matter.
@Centril
Centril / keyword_policy.md
Created April 29, 2018 19:34
Keyword policy permalink

Keyword policy

Upsides of proper keywords (with no availability on old editions)

  • Avoid monotonically increasing tech debt
    • In particular, if contextual keywords accumulate over time, their grammatical interactions are going to get continually trickier
  • Forward-compatible with introducing contextual keywords on older editions
  • Forward-compatible with future uses that can’t be contextual
    • In case we decide 1.5 year hence that we want to do something new with the keyword.
  • Arguably can give better error messages
  • Cleaner
@Centril
Centril / constraint-kinds.md
Created March 5, 2018 20:29 — forked from withoutboats/constraint-kinds.md
Constraint Kinds in Rust

Notes on adding Constraint Kinds to Rust

Background: Constraint Kinds

a trait can be thought of as a type operator generating a "constraint" - what in Rust would usually be called a bound. For example:

// Declares a new item `Foo` with kind `type -> constraint`
trait Foo { }
@Centril
Centril / const_trait_system.rs
Created December 4, 2017 18:55
Const Trait System
//******************************************************************************
// "const_trait_system"
//******************************************************************************
/*
Dependency DAG of proposal:
[A, B] -> []
[C] -> [B] and/or [A] -- NOTE: C is moot without B or A.
[D, E] -> [B]
@Centril
Centril / data.rs
Created September 17, 2017 21:04
Rust: A write up on various pointers for str.
fn main() {
use std::mem::{size_of, size_of_val};
let susize = size_of::<usize>();
// usize is size_t.
// "hello" is in static memory, x is on the stack and like: (char*, usize).
// &'static str is a fat pointer.
// It is not null terminated.
@Centril
Centril / box_callback.rs
Last active May 17, 2017 15:05
Rust: Sending callbacks in struct to a scoped thread with Box
#![feature(core)]
#![feature(std_misc)]
use std::thread::{Thread, JoinGuard};
fn callback(v: usize) -> usize { v * 2 }
struct S {
cb: Box<Fn(usize) -> usize + Send>,
}
@Centril
Centril / keybase.md
Created January 9, 2017 08:32
keybase.md

Keybase proof

I hereby claim:

  • I am Centril on github.
  • I am centril (https://keybase.io/centril) on keybase.
  • I have a public key whose fingerprint is 17DC 71EF 7AD7 4032 4B5D 112E 818B 6F39 DE23 A081

To claim this, I am signing this object: