Skip to content

Instantly share code, notes, and snippets.

if (x > y) {
return true;
}
if (x > y)
return true;
if (x > y) return true;
if (x > y) { return true; }
@diwic
diwic / Rust2018.md
Last active January 11, 2018 07:41
Rust 2018 - Growing in elegance and responsibility

Rust 2018 - Growing in elegance and responsibility

First; I have the utmost respect for the fact that I'm mostly sitting here wishing, while other people do the actual work. But since you asked...

I tend to think of Rust as a language in its teens. We're no longer that child which breaks people's code every other week (like before 1.0), but the language has not really stabilized either. We have many heavy things in flight: GAT, impl Trait, specialisation, NLL, procedural macros, and so on.

And part of growing is learning to say "no". Saying "no" is difficult, because a lot of people might have worked with thinking and evaluating an RFC, believing in it. It's easy to go for the easiest solution that solves a specific problem, without thoroughly consider if there is a more elegant solution that solves a whole class of problems. Even tougher is saying "no" and offering no solution at all (because there is no s

@diwic
diwic / mod.rs
Created September 22, 2017 07:20
Abort landing pad
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
@diwic
diwic / alloca.rs
Last active December 20, 2016 12:15
Safe alloca / stack slice abstraction - I hope?
use std::marker::PhantomData;
use std::{ptr, ops, slice, mem};
#[inline(always)]
fn stack_reserve<T>(count: usize) -> *mut T {
// This is for test purposes only - real version should call an alloca intrinsic instead
let mut v = Vec::with_capacity(count);
let z = v.as_mut_ptr();
mem::forget(v);
z
@diwic
diwic / format_year.rs
Created August 15, 2016 13:17
Calendar example
use chrono::{NaiveDate, Datelike, Duration};
use std::cmp;
fn format_year(y: i32, cols: usize) -> String {
let mut day: Vec<_> = (0..12).into_iter().map(|i| {
let first = NaiveDate::from_ymd(y, i+1, 1);
(first, first - Duration::days(first.weekday().num_days_from_sunday() as i64))
}).collect();
let mut s = String::new();
use std::{ptr, mem, ops};
/// Bx is a Box-like container, but differs in several important ways:
///
/// When constructing a Bx, you first get a BxInit.
/// You can then get an immutable reference to the final Bx's interior,
/// if you promise not to use it until you have called BxInit.init().
///
/// There is no way to get a mutable reference to Bx's interior.
/// Bx does not implement the magic DerefMove trait, so an owner of Bx<T>
use std::{mem, ops};
/// Bx is a Box-like container, but differs in several important ways:
///
/// It can contain "no value" (like Option<Box>), but trying to derefence
/// such a box will panic. Use bx_set to set a value inside the bx.
///
/// You can get an immutable reference to the Bx's interior, if you promise
/// not to use it when no value is in the Bx (bx_unsafe_ref).
/// There is no way to get a mutable reference to Bx's interior.
#![feature(core, alloc, unique)]
use std::{ptr, mem, intrinsics, ops};
use std::rt::heap;
/// Bx is a Box-like container, but differs in several important ways:
///
/// It can contain "no value" (like Option<Box>), but trying to derefence
/// such a box will panic. Use bx_set to set a value inside the bx.
///
use std::cell::Cell;
use std::fmt::{self, Display};
use std::collections::HashSet;
const ORDER: usize = 3;
const OR2: usize = ORDER * ORDER;
const OR4: usize = OR2 * OR2;
#[derive(Copy, Clone, Debug)]
struct SCell {
extern crate test;
use std::cell::{RefCell, UnsafeCell};
use std::rc::Rc;
use test::Bencher;
struct Foo {
name: String
}