This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(libc)] | |
#![feature(cstr_memory)] | |
extern crate libc; | |
use std::ffi::CString; | |
use std::mem; | |
#[repr(C)] | |
pub struct RubyArray { | |
len: libc::size_t, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(libc)] | |
extern crate libc; | |
use std::mem; | |
#[repr(C)] | |
pub struct RubyArray { | |
len: libc::size_t, | |
data: *const libc::c_void, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[no_mangle] | |
pub extern fn print_chars() { | |
for i in 33..126 { | |
println!("{:?}", std::char::from_u32(i).unwrap()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
module Scrape | |
extend FFI::Library | |
ffi_lib './target/debug/libscrape.dylib' | |
class TwoNumbers < FFI::Struct | |
layout :first, :uint32, | |
:second, :uint32 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
module Scrape | |
extend FFI::Library | |
ffi_lib './target/debug/libscrape.dylib' | |
class TwoNumbers < FFI::Struct | |
layout :first, :int32, | |
:second, :int32 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct TwoNumbers { | |
first: i32, | |
second: i32, | |
} | |
#[no_mangle] | |
pub extern fn add_struct_vals(numbers: TwoNumbers) -> i32 { | |
numbers.first + numbers.second | |
} |