This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(try_blocks, label_break_value)] | |
macro_rules! maybe { | |
($($t:tt)*) => { | |
'maybe_scope: loop { | |
break 'maybe_scope (try { | |
break 'maybe_scope {$($t)*} | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn deploy_metadata(tx: &rusqlite::Transaction) -> Result<(), Error> { | |
tx.execute("CREATE TABLE spire_metadata (version INTEGER NOT NULL)", rusqlite::NO_PARAMS) | |
.map_err(crate::database_error_context("deploy metadata table"))?; | |
tx.execute("INSERT INTO spire_metadata (version) VALUES (0)", rusqlite::NO_PARAMS) | |
.map_err(crate::database_error_context("populate metadata table"))?; | |
Ok(()) | |
} | |
fn database_is_empty(tx: &rusqlite::Transaction) -> Result<bool, Error> { | |
let table_count: i64 = tx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Identity {} | |
struct Carrier; | |
impl Identity for Carrier {} | |
fn witness<T>(_: T) -> impl Identity { Carrier } | |
macro_rules! witness { () => { witness(|| {}) } } | |
fn main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops; | |
fn main() { | |
let a = MyNum(23); | |
let b = MyNum(42); | |
println!("{:?}", a /plus/ b); | |
} | |
#[derive(Debug)] | |
struct MyNum(i64); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! gen_strmapped_enum { | |
( $name:ident: $($variant:ident => $value:expr,)+ ) => { | |
#[derive( Copy, Clone, Eq, PartialEq, Debug )] | |
pub enum $name { | |
$( $variant, )+ | |
} | |
impl $name { | |
fn from_str(value: &str) -> Option<$name> { | |
match value { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature( core )] | |
#![allow( unused_mut )] | |
pub trait IterInto: Iterator { | |
type Item; | |
fn into<T>(mut self, target: T) | |
where T: IterIntoTarget<<Self as IterInto>::Item>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
#![experimental] | |
use std::num::Zero; | |
#[deriving(Show, PartialEq, PartialOrd, Ord, Eq, Clone)] | |
pub enum CheckedErr { | |
WrapErr, | |
DivByZeroErr, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
use File::Basename; | |
use FFI::Raw; | |
my $lib = join '/', dirname(__FILE__), 'rust-code'; | |
system("rustc --crate-type dylib --opt-level 3 -o $lib.so $lib.rs") | |
and die "Aborting due to build failure\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait ApplyClosure { | |
fn tangent<'a>(mut self, op: |&mut Self|) -> Self { | |
op(&mut self); | |
self | |
} | |
fn apply<R>(self, op: |Self| -> R) -> R { | |
op(self) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![crate_id = "check"] | |
#![crate_type = "bin"] | |
#![feature(macro_rules)] | |
#[deriving(Show)] | |
enum CheckedVariant<T> { | |
Checked(T), | |
NaN, | |
} |
NewerOlder