Skip to content

Instantly share code, notes, and snippets.

#include "test_lib.h"
int main(int argc, char* argv[]) {
print_hello();
}
@ekse
ekse / CMakeLists.txt
Last active April 27, 2018 04:14
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(CMakeRustSample)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
enable_language(Rust)
include(CMakeCargo)
include_directories("include")
#ifndef TEST_LIB
#define TEST_LIB
#ifdef __cplusplus
extern "C" {
#endif
void print_hello();
#ifdef __cplusplus
cargo_build(NAME test-lib)
#[no_mangle]
pub extern "C" fn print_hello() {
println!("hello world!");
}
[lib]
crate-type = ["staticlib"]
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
enable_language(Rust)
include(CMakeCargo)
cmake_minimum_required(VERSION 3.0)
project(CMakeRustSample)
add_executable(helloworld main.cpp)
int main(int argc, char* argv[]) {
return 0;
}
@ekse
ekse / ws.rs
Created January 31, 2018 19:25
extern crate ws;
use ws::{WebSocket, Sender, Handler, Factory, Message};
fn gimme_websocket() -> WebSocket<Factory<Handler = FnMut(Sender) -> (Fn(Message) -> ws::Result<()>)>> {
let f = |output: Sender| {
// The closure handler needs to take ownership of output
let handler = move |msg| {
println!("got '{}' ", msg);
};