Skip to content

Instantly share code, notes, and snippets.

@jpastuszek
jpastuszek / playground.rs
Created May 16, 2019 11:01 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::marker::PhantomData;
use std::convert::TryFrom;
use std::convert::TryInto;
#[derive(Debug)]
struct ConversionError;
struct ResultSet<T> {
column_names: Vec<String>,
rows: Vec<Vec<i32>>,
@jpastuszek
jpastuszek / playground.rs
Created May 16, 2019 10:34 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::rc::Rc;
struct ResultSet {
column_names: Rc<Vec<String>>,
rows: Vec<Vec<i32>>,
}
impl ResultSet {
fn pop(&mut self) -> Option<Row> {
self.rows.pop().map(|columns| Row {
@jpastuszek
jpastuszek / playground.rs
Created May 16, 2019 10:29 — forked from rust-play/playground.rs
Code shared from the Rust Playground
struct ResultSet {
column_names: Vec<String>,
rows: Vec<Vec<i32>>,
}
impl ResultSet {
fn get<'rs>(&'rs self, row_no: usize) -> Option<Row<'rs>> {
self.rows.get(row_no).map(|columns| Row {
column_names: self.column_names.as_slice(),
columns: columns.as_slice(),
@jpastuszek
jpastuszek / playground.rs
Created February 22, 2019 09:58 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::io;
struct Connection;
struct Handle<'c>(&'c Connection);
struct Statement<'c>(&'c Connection);
struct Rows<'c, 'l>(Statement<'c>, &'l mut Handle<'c>);
@jpastuszek
jpastuszek / playground.rs
Last active February 22, 2019 10:10 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::io;
struct Connection;
struct Handle<'c>(&'c Connection);
struct Statement<'c>(&'c Connection);
struct Rows<'c, 'l>(Statement<'c>, &'l mut Handle<'c>);
@jpastuszek
jpastuszek / tokio_timer_thread.rs
Created May 3, 2018 08:21
Manual setup of tokio_timer thread
use tokio_timer::timer::Timer;
use tokio_timer;
use tokio_executor::park::{Park, Unpark, ParkThread};
use tokio_executor::Enter;
use futures::sync::oneshot;
use futures::Future;
use std::thread;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
@jpastuszek
jpastuszek / async_file_io_streaming.rs
Created May 3, 2018 08:20
Reading seekable and non-seekcable streams with dedicated thread to future-rs streams of buffers with buffer reuse
use std::io::{self, Read, Seek, SeekFrom};
use std::fmt::Display;
use futures::prelude::*;
use futures::sync::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
use futures::unsync::mpsc::unbounded as unsync_unbounded;
use futures::stream::iter_ok;
use futures::future::{FutureResult, ok};
use futures::future::lazy;
use std::thread;
use std::env;
@jpastuszek
jpastuszek / throughput.rs
Last active May 3, 2018 08:26 — forked from rust-play/playground.rs
Average per second over time window
use std::collections::VecDeque;
use std::time::{Instant, Duration};
#[derive(Debug)]
struct Throughput {
window: VecDeque<u64>,
front: Instant,
duration: Duration,
}
@jpastuszek
jpastuszek / playground.rs
Last active September 22, 2017 09:50 — forked from anonymous/playground.rs
Rust typestate
use std::fmt::Debug;
#[derive(Debug)]
struct Server<State> where State: ServerState + Debug {
work_dir: String,
state: State
}
impl Server<Starting> {
fn start(self) -> Server<Running> {
[15:43:26] [Server thread/INFO] [FML]: Loading dimension 2 (serv_mods) (net.minecraft.server.dedicated.DedicatedServer@67205199)
[15:43:26] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: net.minecraft.world.biome.Biome.func_185361_o()I
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_25]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_25]
at net.minecraft.util.Util.func_181617_a(SourceFile:47) [h.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:679) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:384) [lh.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:624) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]