Skip to content

Instantly share code, notes, and snippets.

View Kerollmops's full-sized avatar
🍼
Meilisearch needs care

Clément Renault Kerollmops

🍼
Meilisearch needs care
View GitHub Profile
@Kerollmops
Kerollmops / Aaa.rs
Last active November 10, 2017 14:30
Little hack to display default values in the doc. (don't forget to `cargo test --doc`)
#[derive(Debug, PartialEq, Eq)]
pub struct Aaa {
pub field1: usize,
pub field2: i32,
}
impl Default for Aaa {
/// ```
/// # use aaa::Aaa;
/// # let a =
#[derive(Debug)]
struct Person {
name: String,
age: u32,
}
impl Person {
fn new(name: String, age: u32) -> Self {
// return Person { name: name, age: age };
Self { name, age }
@Kerollmops
Kerollmops / lib.mir.rs
Last active January 14, 2018 14:37
test on impl
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn <impl at src/lib.rs:5:1: 9:2>::from(_1: i16) -> Koko {
let mut _0: Koko; // return place
let mut _2: i16;
bb0: {
StorageLive(_2); // bb0[0]: scope 0 at src/lib.rs:7:23: 7:28
_2 = _1; // bb0[1]: scope 0 at src/lib.rs:7:23: 7:28
_0 = Koko { field: move _2 }; // bb0[2]: scope 0 at src/lib.rs:7:9: 7:30
extern crate bindgen;
use std::env;
use std::path::{Path, PathBuf};
fn main() {
println!("cargo:rustc-link-search=framework=/System/Library/Frameworks/");
println!("cargo:rustc-link-lib=framework=OpenCL");
let headers = env::var("CARGO_MANIFEST_DIR").unwrap() + "/opencl22/CL/";
@Kerollmops
Kerollmops / corona-bench.txt
Created February 3, 2018 23:06
Corona benchmark result sorted (thanks to https://stackoverflow.com/a/9471139/1941280)
test async ... bench: 25,129,522 ns/iter (+/- 1,948,456)
test async_cpupool ... bench: 13,895,220 ns/iter (+/- 2,412,441)
test async_cpupool_cpus ... bench: 16,449,300 ns/iter (+/- 7,062,024)
test async_cpupool_many ... bench: 14,118,352 ns/iter (+/- 3,170,100)
test async_cpus ... bench: 11,057,663 ns/iter (+/- 1,546,785)
test async_many ... bench: 14,304,595 ns/iter (+/- 1,966,185)
test corona ... bench: 34,898,721 ns/iter (+/- 204,006,257)
test corona_blocking_wrapper ... bench: 35,851,174 ns/iter (+/- 76,716,240)
test corona_blocking_wrapper_cpus ... bench: 12,601,478 ns/iter (+/- 1,368,466)
test corona_blocking_wrapper_many ... bench: 20,098,071 ns/iter (+/- 84,982,750)

Core Coding Standard

Coding practices are a source of a lot of arguments among programmers. Coding standards, to some degree, help us to put certain questions to bed and resolve stylistic debates. No coding standard makes everyone happy. (And even their existence is sure to make some unhappy.) What follows are the standards we put together on the Core team, which have become the general coding standard for all programming teams on new code development. We’ve tried to balance the need for creating a common, recognizable and readable code base with not unduly burdening the programmer with minor code formatting concerns.

Table Of Contents

@Kerollmops
Kerollmops / kero_solution.rs
Created March 22, 2018 09:11
Different solutions to create a KernelBuilder
pub enum Arg {
Int(i32),
Float(f32),
String(String),
Ptr(isize),
}
pub enum KernelError {
KernelInvalid,
}
@Kerollmops
Kerollmops / split-first.rs
Created August 6, 2018 12:06
The `split_first` function for any iterator
// prefer using IntoIterator ?
fn split_first<T, I>(mut iter: I) -> Option<(T, I)>
where I: Iterator<Item=T>
{
match iter.next() {
Some(first) => Some((first, iter)),
None => None,
}
}
@Kerollmops
Kerollmops / all-eq.rs
Created August 6, 2018 12:07
A function to test if all values of a slice are equal (to the first element).
fn all_eq<T: Eq>(slice: &[T]) -> bool {
match slice.split_first() {
Some((first, others)) => others.iter().all(|x| x == first),
None => true,
}
}
#[test]
fn all_eq_easy_eq() {
assert!(all_eq(&[1, 1, 1, 1, 1]));
@Kerollmops
Kerollmops / group-by-generic-function.rs
Created January 31, 2019 22:06
Generic function type thta is in fact a function pointer (`fn` != `Fn`)
fn linear_group(&self) -> LinearGroupBy<T, fn(&T, &T) -> bool>
where T: Ord
{
LinearGroupBy::new(self, |a, b| a == b)
}