Skip to content

Instantly share code, notes, and snippets.

Jarred Nicholls jnicholls

Block or report user

Report or block jnicholls

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
jnicholls /
Created Sep 11, 2019
A message stream example, using an underlying bincode bi-directional stream, which in turn uses tokio-serde under that.
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use bincode::Error;
use bytes::{Bytes, BytesMut};
use futures::{Sink, Stream, TryStream};
use pin_utils::unsafe_pinned;
use serde::{Deserialize, Serialize};
use tokio_serde::{Deserializer, FramedRead, FramedWrite, Serializer};
View gist:8a22471f77ffa3c06c21200bcbc91cb1
struct Device {
pub data: u32
impl Device {
pub fn new() -> Self { Device { data: 0 } }
pub fn async(&mut self) -> BoxFuture<(), ()> {
async_fn().and_then(|result| { = result;
View gist:6cf250762e31809e1451431f1d258619
```Compiling syntex v0.35.0
Compiling quasi v0.12.0
Compiling aster v0.18.0
Compiling quasi_codegen v0.12.0
Compiling serde_codegen v0.7.10 (
error[E0463]: can't find crate for `syntex`
--> /home/vagrant/.multirust/toolchains/stable/cargo/git/checkouts/serde-1cbd136c2e06ab68/8a09f05644ad286e5a18c714ec1af58ed90d1d8b/serde_codegen/
3 | extern crate syntex;
| ^^^^^^^^^^^^^^^^^^^^ can't find crate
View gist:5f2d6f58b1885024d0f1744af6bbfb32
"serde_codegen:0.7.10" = { git = "", rev = "8a09f05644ad286e5a18c714ec1af58ed90d1d8b" }
View gist:aaa0652673439b3d0603
for x in 0..10 {
let promise = Promise::<u32,&str>::new(move || {
match x {
0 => Err("Division by zero"),
_ => Ok(x * 2)
}).success(move |res| {
assert_eq!(res, x * 2);
Ok(res * 2)
}).success(|res| {
View gist:b6eedb3b46e11125b300
macro_rules! recurse {
($prop_name:ident: $prop_type:ty) => (
println!("{}: {}", stringify!($prop_name), stringify!($prop_type));
($($prop_name:ident: $prop_type:ty),*) => (
recurse!($($prop_name: $prop_type),*);
fn main() {
View gist:57cef03b7a33497125e0
running 1 test
test it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Doc-tests ironentities
/Users/jarred/blah/rust/src/ 2:18 error: multiple rlib candidates for `log` found
/Users/jarred/blah/rust/src/ extern crate log;
/Users/jarred/blah/rust/src/ 2:18 note: candidate #1: /Users/jarred/blah/rust/target/debug/deps/liblog-045aab9d45b4c031.rlib
View gist:76393584b9fe4f645e76
QString::Data *QString::fromLatin1_helper(const char *str, int size)
Data *d;
if (!str) {
d = Data::sharedNull();
} else if (size == 0 || (!*str && size < 0)) {
d = Data::allocate(0);
} else {
if (size < 0)
size = qstrlen(str);
View gist:7771803
SemaphoreSlim signal = new SemaphoreSlim(0, 1);
// set signal in event
// wait for signal somewhere else
await signal.WaitAsync();
View gist:5886571
How Do Court Reporters Keep Straight Faces?
These are from a book called Disorder in the Courts and are things people actually said in court, word for word, taken down and published by court reporters that had the torment of staying calm while the exchanges were taking place.
ATTORNEY: What was the first thing your husband said to you that morning?
WITNESS: He said, 'Where am I, Cathy?'
ATTORNEY: And why did that upset you?
WITNESS: My name is Susan!
ATTORNEY: What gear were you in at the moment of the impact?
You can’t perform that action at this time.