Skip to content

Instantly share code, notes, and snippets.

View mfpiccolo's full-sized avatar

Mike Piccolo mfpiccolo

View GitHub Profile
#![feature(test)]
extern crate hyper;
extern crate test;
use hyper::Client;
use std::io::Read;
extern crate time;
#[no_mangle]
pub extern fn run_threads() {
let start_time = time::now();
require 'ffi'
module Scrape
extend FFI::Library
ffi_lib './target/debug/libscrape.dylib'
class FromRustArray < FFI::Struct
layout :len, :size_t, # dynamic array layout
:data, :pointer #
#![feature(libc)]
#![feature(cstr_memory)]
extern crate libc;
use std::ffi::CString;
use std::mem;
#[repr(C)]
pub struct RubyArray {
len: libc::size_t,
#![feature(libc)]
extern crate libc;
use std::mem;
#[repr(C)]
pub struct RubyArray {
len: libc::size_t,
data: *const libc::c_void,
}
#[no_mangle]
pub extern fn number_to_char_array() -> Vec<String> {
let mut utf_chars: Vec<String> = vec![];
for i in 33..126 {
let maybe_char: Option<char> = std::char::from_u32(i);
utf_chars.push(maybe_char.unwrap().to_string());
}
utf_chars
}
#[no_mangle]
pub extern fn print_chars() {
for i in 33..126 {
println!("{:?}", std::char::from_u32(i).unwrap());
}
}
require 'ffi'
module Scrape
extend FFI::Library
ffi_lib './target/debug/libscrape.dylib'
class TwoNumbers < FFI::Struct
layout :first, :uint32,
:second, :uint32
end
pub struct TwoNumbers {
first: i32,
second: i32,
}
impl TwoNumbers {
fn plus_one_to_each(self) -> TwoNumbers {
let mut tn = self;
tn.first += 1;
tn.second += 1;
require 'ffi'
module Scrape
extend FFI::Library
ffi_lib './target/debug/libscrape.dylib'
class TwoNumbers < FFI::Struct
layout :first, :int32,
:second, :int32
end
pub struct TwoNumbers {
first: i32,
second: i32,
}
#[no_mangle]
pub extern fn add_struct_vals(numbers: TwoNumbers) -> i32 {
numbers.first + numbers.second
}