This file contains hidden or 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_to_str)] | |
#![feature(cstr_memory)] | |
extern crate libc; | |
use std::ffi::{CStr, CString}; | |
#[no_mangle] | |
pub extern fn ruby_reverse(s: *const libc::c_char) -> *const libc::c_char { | |
let rust_cstr = unsafe { CStr::from_ptr(s) }; // &std::ffi::c_str::CStr | |
let str = rust_cstr.to_str().unwrap(); // &str | |
let string: String = str.chars().rev().collect(); // collections::string::String |
This file contains hidden or 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
extern crate libc; | |
use std::ffi::CStr; | |
pub extern fn ruby_reverse(s: *const libc::c_char) -> *const libc::c_char { | |
let rust_cstr = unsafe { CStr::from_ptr(s) }; // &std::ffi::c_str::CStr | |
let str = rust_cstr.to_str().unwrap(); // &str | |
let string: String = str.chars().rev().collect(); // collections::string::String | |
// convert and return for ffi ruby module | |
} |
This file contains hidden or 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
extern crate libc; | |
pub extern fn reverse(s: *const libc::c_char) -> *const libc::c_char { | |
// reverse string and return | |
} |
This file contains hidden or 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
fn reverse(s: String) -> String { | |
s.chars().rev().collect() | |
} |
This file contains hidden or 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
#[test] | |
fn it_works() { | |
assert!( | |
reverse(“Don’t use palindrome”.to_string()) == “emordnilap esu t’noD” | |
); | |
} |
This file contains hidden or 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
fn reverse(s: String) -> String { | |
s.chars().rev() | |
} |
This file contains hidden or 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
fn reverse(s: String) -> String { | |
// reverse string here | |
} | |
#[test] | |
fn it_works() { | |
assert!( | |
reverse(“Don’t use palindrome”) == "emordnilap esu t'noD"; | |
) | |
} |
This file contains hidden or 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
"abcde".chars.reduce{|s,c| c + s } # => "edcba" |
This file contains hidden or 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
'this is a string'.class # => String | |
"this is a string".class # => String | |
%{this is a string}.class # => String | |
string = <<END | |
this is a string | |
END | |
string.class = # => String |
This file contains hidden or 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
#[test] | |
fn it_works() { | |
assert!(true); | |
} |