Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_array_assume_init)]
use std::{
iter::FromIterator,
mem::MaybeUninit
};
fn main() {
let bar = vec![1,2,3];
@bstrie
bstrie / main.rs
Last active September 1, 2019 21:49
lazy static of the future
// This type is a replacement for the macro provided by the lazy_static crate
use lazy::Lazy;
use std::collections::HashMap;
static GLOBAL_MAP: Lazy<HashMap<u32, &str>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert(0, "foo");
m.insert(1, "bar");
m.insert(2, "baz");
m
fn redis_insert_account(
&self,
specified_id: Option<u64>,
account: AccountDetails,
) -> Box<dyn Future<Item = Account, Error = ()> + Send> {
let connection = self.connection.clone();
let routing_table = self.routes.clone();
let encryption_key = self.encryption_key.clone();
// Instead of storing the incoming secrets, we store the HMAC digest of them
error[E0599]: no method named `and_then` found for type `futures::future::either::Either<std::result::Result<(redis::async::SharedConnection, account::Account), _>, futures::future::and_then::AndThen<futures::future::and_then::AndThen<impl futures::future::Future, std::result::Result<account::Account, ()>, [closure@crates/interledger-store-redis/src/store.rs:320:31: 323:22 account:_]>, futures::future::and_then::AndThen<futures::future::map_err::MapErr<std::boxed::Box<dyn futures::future::Future<Item = (redis::async::SharedConnection, std::vec::Vec<bool>), Error = redis::types::RedisError> + std::marker::Send>, [closure@crates/interledger-store-redis/src/store.rs:341:38: 346:30]>, std::result::Result<(redis::async::SharedConnection, account::Account), ()>, [closure@crates/interledger-store-redis/src/store.rs:348:33: 355:34 keys:_, account:_]>, [closure@crates/interledger-store-redis/src/store.rs:325:31: 357:22 btp_incoming_token_hmac:_, http_incoming_token_hmac:_, connection:_]>>` in the current scope
-->
Compiling countess v0.1.0 (C:\Users\Ben\code\rust\countess)
error[E0412]: cannot find type `ItemFn` in module `syn`
--> src\lib.rs:7:54
|
7 | let input = syn::parse_macro_input!(item as syn::ItemFn);
| ^^^^^^ not found in `syn`
error: aborting due to previous error
#include <iostream>
#include <vector>
int main() {
std::vector<int> v { 2, 3, 4 };
for(auto i: v) {
if (i % 2 == 0) {
v.push_back(i * -1);
}
}
struct Foo {
a: (int, int)
}
fn main() {
let foo = Foo { a: (1, 2) };
let Foo { a: (x, y) } = foo;
println!("{} {}", x, y);
}
@bstrie
bstrie / wiki5.rs
Last active January 4, 2016 01:38
/* This program defines a recursive datastructure and implements methods upon it.
Recursive datastructures require a layer of indirection, which is provided here
by a unique pointer, indicated by the tilde `~` operator. These are analogous to
the C++ library type `std::unique_ptr`, though with more static safety guarantees. */
fn main() {
let list = ~Node(1, ~Node(2, ~Node(3, ~Empty)));
println!("Sum of all values in the list: {:i}.", list.multiply_by(2).sum());
}
// An `enum` defines a type that may be one of several different kinds of values at runtime.
fn main() {
let argv = std::os::args();
let (x, y, z) = match argv {
[filename, arg1, arg2, arg3, ..rest] => (arg1, arg2, arg3),
_ => fail!("At least three arguments expected.")
};
}
fn integral(f: &|f32|->f32, p: u32, a: f32, b: f32) -> f32 {
if p == 1 {
(b-a) * ((*f)(a) + 4.0 * (*f)((a+b)/2.0) + (*f)(b))/6.0
}
else {
let mid = (a+b)/2.0;
integral(f, p-1, a, mid) + integral(f, p-1, mid, b)
}
}