Skip to content

Instantly share code, notes, and snippets.

pub fn query_and_collect<T, F, C>(&self, sql: &str, params: &[&ToSql], f: F) -> SqliteResult<C>
where F: Fn(SqliteRow) -> T + Copy, // FIXME: is the Copy really necessary?
C: FromIterator<T> {
let mut statement = try!(self.prepare(sql));
statement
.query(params)
.and_then(|rows| {
rows
.map(|row| {
@marcusklaas
marcusklaas / gist:2f9f3a7d4ee78d1ee2d2
Created May 6, 2015 12:33
weird conflicting implementation error
/// A trait for types that can be created from a SQLite value.
pub trait FromSql {
unsafe fn column_result(stmt: *mut sqlite3_stmt, col: c_int) -> SqliteResult<Self>;
}
impl<'a, T> FromSql for T where T: convert::From<&'a str> {
unsafe fn column_result(stmt: *mut sqlite3_stmt, col: c_int) -> SqliteResult<T> {
let c_text = ffi::sqlite3_column_text(stmt, col);
if c_text.is_null() {
Ok(T::from(""))
@marcusklaas
marcusklaas / gist:d81999a1b1738e48387a
Created August 10, 2015 22:03
spam analysis by spamassassin
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: by marcusklaas.nl (Postfix, from userid 1005)
id 80A981A0330; Mon, 10 Aug 2015 23:34:32 +0200 (CEST)
Received: from localhost by VBND001.cs1local
with SpamAssassin (version 3.4.0);
Mon, 10 Aug 2015 23:34:32 +0200
From: "MICHAEL SMITH"<[email protected]>
To: undisclosed-recipients:;
pub struct ListItems<'a, I, F1, F2, F3>
where I: Iterator
{
codemap: &'a CodeMap,
inner: Peekable<I>,
get_lo: F1,
get_hi: F2,
get_item_string: F3,
prev_span_end: BytePos,
next_span_start: BytePos,
pub trait AsRev {
fn as_rev(&self) -> &ListItem;
}
impl AsRev for ListItem {
fn as_rev(&self) -> &ListItem {
&self
}
}
@marcusklaas
marcusklaas / lisp-parser.rs
Last active May 9, 2017 19:15
Very simple lisp parser/ evaluater in Rust
use std::env;
use std::process::exit;
use std::str::Chars;
use std::iter::Peekable;
#[derive(Debug, PartialEq, Eq)]
enum LispExpr {
Integer(u64),
Operator(String),
SubExpr(Vec<LispExpr>),