Skip to content

Instantly share code, notes, and snippets.

View U007D's full-sized avatar

Brad Gibson U007D

View GitHub Profile
enum State {
On,
Off,
}
trait Foo {
const STATE: State;
}
struct A;
@U007D
U007D / roll_validator.rs
Last active July 15, 2018 00:58
evolution from iterative to functional validator for bgk
//does not work as intended :(
#[inline]
pub(super) fn validate_frame(roll: u8) -> Result<u8> {
let mut frame_validator = || -> Error {
for frame in Game::FIRST_FRAME..=Game::LAST_FRAME {
let first_roll = roll;
yield Ok(first_roll);
// this frame has a second roll if it's the last frame OR if first roll was not a strike
@U007D
U007D / 1.26.0_stabilizations.rs
Created March 30, 2018 12:36
Rust 1.26.0 stablizations
brad@SocratesV:~/Development/rust/rust$ rg 1.26.0
src/bootstrap/channel.rs
27:pub const CFG_RELEASE_NUM: &str = "1.26.0";
src/libstd/lib.rs
437:#[stable(feature = "i128", since = "1.26.0")]
467:#[stable(feature = "i128", since = "1.26.0")]
src/libstd/path.rs
909:#[stable(feature = "fused", since = "1.26.0")]
fn main() {
let opt = Opt::from_args();
if let Err(err) = run(&opt) {
eprintln!("error: {}", err);
std::process::exit(1);
}
}
// ->
@U007D
U007D / playground.rs
Created February 14, 2018 14:56 — forked from anonymous/playground.rs
Rust code shared from the playground
use std::fmt;
#[derive(Debug, Clone, Copy)]
pub enum CardinalPoint {
North = 0x2191, // ↑
NorthEast = 0x2197, // ↗
East = 0x2192, // →
SouthEast = 0x2198, // ↘
South = 0x2193, // ↓
SouthWest = 0x2199, // ↙
@U007D
U007D / playground.rs
Created February 14, 2018 14:56 — forked from anonymous/playground.rs
Rust code shared from the playground
use std::fmt;
#[derive(Debug, Clone, Copy)]
pub enum CardinalPoint {
North = 0x2191, // ↑
NorthEast = 0x2197, // ↗
East = 0x2192, // →
SouthEast = 0x2198, // ↘
South = 0x2193, // ↓
SouthWest = 0x2199, // ↙
// Crazy macro by bluss
// Split a stream of tt's into before and after `==`
macro_rules! split_eq {
($sep: tt ($m: ident $($args:tt)*) [$($stack:tt)*] $x: tt) => {
$m ! ($($args)* $($stack)* $x $sep)
};
($sep: tt ($m: ident $($args:tt)*) [$($stack:tt)*] $x: tt == $($rest: tt)*) => {
$m ! ($($args)* $($stack)* $x $sep $($rest)*)
};
@U007D
U007D / ada.rs
Last active January 12, 2018 17:36
Errors
/// crate gpio_mmap
/// mod gpio_mmap
pub trait GpioMmap {
type Error: Fail;
type Register;
fn new(...) -> Result<Self, Self::Error> where Self: Sized;
fn registers(&self) -> &[Self::Register];
}
extern crate libc;
use std::collections::HashMap;
use std::any::TypeId;
use std::string::ToString;
use std::any::Any;
use std::io::{self, Write};
use libc::{EXIT_SUCCESS, EXIT_FAILURE};
type Result<T> = std::result::Result<T, Box<std::error::Error>>;
@U007D
U007D / hkt_lens.rs
Created November 29, 2017 14:50
Simulated HKT in Rust via type lenses
// Project the generics out into an HList
pub trait Unapply {
type Out: ty::Tm<ty::List<ty::Star>> + HList;
}
// Reapply the type to a fresh set of generics
pub trait Reapply<Args: ty::Tm<ty::List<ty::Star>>>
: Unapply
{
type Out: Unapply<Out = Args>;