Skip to content

Instantly share code, notes, and snippets.

Steven Blenkinsop stevenblenkinsop

Block or report user

Report or block stevenblenkinsop

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View go2draft-contracts-response-auxiliary-types.md

Response to the Go 2 Contracts Draft Design:
Auxiliary Types

Steven Blenkinsop
September 1, 2018

Summary

This response concerns generic types which are found in the signatures of methods on the inputs to a contract which are not themselves inputs to the contract, for example the type of elem in elem := stack.Pop(), where the type of stack is an input to the contract. It suggests formalizing these types as part of the signature of a contract, like

@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active Mar 20, 2016 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
use std::any::Any;
trait Schema {
fn eq(&self, other: &Schema) -> bool;
fn as_any(&self) -> &Any;
}
impl PartialEq<Schema> for Schema {
fn eq(&self, other: &Schema) -> bool {
Schema::eq(self, other)
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active Mar 19, 2016 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
use std::any::Any;
trait Schema {
fn eq(&self, other: &Schema) -> bool;
fn as_any(&self) -> &Any;
}
impl<'a, 'b> PartialEq<Schema+'b> for Schema+'a {
fn eq(&self, other: &(Schema+'b)) -> bool {
Schema::eq(self, other)
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created Nov 8, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
fn old() -> Vec<u8> {
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image.
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image.
for x in 0..8 {
for y in 0..8 {
if raw[x*9+y] > raw[x*9+y+1] {
hash[x] |= 0x1 << y
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active Oct 13, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
fn main() {
#![allow(unused)]
// A borrow can be moved out of the scope where it is created as long as the original value is
// known to live long enough. Here it is assigned to `out`. While `out` is in scope, `x` is
// inaccessible. When `out` goes out of scope, `x` becomes accessible again:
{
fn bar<'a>(x: &'a mut u32) -> &'a mut u32 { x }
let mut x = 1;
{
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active Oct 1, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
fn old() -> Vec<u8> {
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image.
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image.
for x in 0..8 {
for y in 0..8 {
if raw[x*9+y] > raw[x*9+y+1] {
hash[x] |= 0x1 << y
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active Sep 27, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
use std::marker::PhantomData;
struct Nothing;
#[allow(dead_code)]
struct Neg;
struct Zero<T: Num>(PhantomData<T>);
struct One<T: Num>(PhantomData<T>);
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created Aug 25, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
trait T<'a> {
type A;
type Iter: Iterator<Item=Self::A>;
fn new() -> Self;
fn iter(&self) -> Self::Iter;
fn test() where Self: Sized {
let a = <Self as T<'a>>::new();
let _ = a.iter().map(|a| a);
View playground.rs
fn function(_x: &i32) -> &i32 { &5th }
fn main() {
function();
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created Jul 23, 2015 — forked from anonymous/playground.rs
Shared via Rust Playground
View playground.rs
use std::ops::Deref;
fn main() {
let s: &'static str = "hello";
let x: &'static str = &*s;
let y: &'static str = s.deref(); // <-- lifetime error
}
You can’t perform that action at this time.