Skip to content

Instantly share code, notes, and snippets.

View allengeorge's full-sized avatar

Allen George allengeorge

  • New York, NY, USA
View GitHub Profile
@allengeorge
allengeorge / errors.rs
Created November 17, 2016 17:36
Errors while trying to compile some code...
pub struct TTestSyncClient {
i_prot: Rc<RefCell<Box<TProtocol>>>,
o_prot: Rc<RefCell<Box<TProtocol>>>,
sequence_number: i32,
}
impl TTestSyncClient {
fn send_testVoid(&mut self) -> rift::Result<()> {
self.sequence_number = self.sequence_number + 1;
let message_ident = TMessageIdentifier { name:"testVoid".to_owned(), message_type: TMessageType::Call, sequence_number: self.sequence_number };
impl<T: Transport> BufferedTransport<T> {
fn get_bytes(&mut self) -> io::Result<&[u8]> {
if self.rpos == self.rbuf.len() {
self.rpos = 0;
self.rcap = try!(self.underlying.read(&mut self.rbuf));
}
Ok(&self.rbuf[self.rpos..self.rcap])
}
+- protocol
| +- mod.rs
| +- binary.rs <--- I want to use Transport (from transport module here)
+- transport
| +- mod.rs <--- pub trait Transport defined here
+- lib.rs
@allengeorge
allengeorge / deref.rs
Created October 9, 2016 15:27
Confused about Box references
pub fn iter<'a>(&'a self) -> Iter<'a, T> {
let y: Option<&Box<Node<T>>> = self.head.as_ref();
Iter { next: y.map(|b: &Box<Node<T>>| {
let n: Node<T> = *b;
&n
})
}
}
fn header_name<T: Header>() -> &'static str {
<T as Header>::header_name()
}
#![allow(dead_code)]
use std::f32::INFINITY;
use std::sync::Arc;
use std::thread;
use std::sync::mpsc::channel;
struct Store {
name: String,
items: Vec<Item>,
#![allow(dead_code)]
use std::f32::INFINITY;
use std::sync::{Arc, Mutex};
use std::thread;
struct Store {
name: String,
items: Vec<Item>,
}
let best: (Option<String>, f32) = (None, INFINITY);
let best = Arc::new(Mutex::new(best));
let mut handles = vec![];
for store in stores {
let best = best.clone();
let shopping_list = shopping_list.clone();
handles.push(thread::spawn(move || {
let sum = store.total_price(&shopping_list);
let (ref mut prev_best_store, ref mut prev_best_price) = *best.lock().unwrap();
java.lang.RuntimeException: java.lang.AssertionError:
Expecting:
<"">
to contain:
<"Hello, world!">
at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:177)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:642)
at com.intellij.testFramework.EdtTestUtilKt.runInEdtAndWait(EdtTestUtil.kt:42)
at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:29)
at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.kt)
// Copyright 2016 Allen A. George.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,