Skip to content

Instantly share code, notes, and snippets.

View dirvine's full-sized avatar

David Irvine dirvine

View GitHub Profile
@seanjensengrey
seanjensengrey / rust-python-cffi.md
Last active April 3, 2024 11:55
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
@dirvine
dirvine / myclass.h
Last active December 19, 2015 07:49
FullyOrdered c++11 class (assume that will work in msvc as well as gcc clang)
#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <tuple>
#include <utility>
template <typename T, typename U>
struct MyClass {
T first;
U second;
@rkennedy
rkennedy / boost-join-example.cpp
Created January 27, 2012 02:48
Demonstration of Boost.Range to join multiple containers into a single sequence
#include <vector>
#include <deque>
#include <string>
#include <iostream>
#include <boost/range/join.hpp>
int main() {
// Iterated-over containers can be different types, as long as the
// value types are the same (string, in this case).
std::vector<std::string> vec1 = { "one", "two", "three" };