Permalink
Browse files

Latest Rust state.

  • Loading branch information...
1 parent 43dccb8 commit f4d1f9d319e101b714e991e597c6a5e7631a4fcd @floere committed Oct 26, 2015
View
@@ -2,7 +2,7 @@
extern crate libc;
-use libc::{c_char, uint16_t, int64_t, size_t};
+use libc::{c_char, uint16_t, uint8_t, size_t};
use std::ffi::CString;
// macro_rules! dereflegate {
@@ -86,9 +86,9 @@ fn rust_array_slice_bang(array: &mut Array, offset: usize, amount: usize) -> Box
Box::new(array.slice_bang(offset, amount))
}
-#[no_mangle] pub extern "C"
-fn rust_array_sort_by_bang(array: &Array, block: extern fn(uint16_t) -> int64_t) -> Box<Array> {
- Box::new(array.sort_by(|&a, &b| block(a).cmp(&block(b))))
+#[no_mangle] pub extern "C" // FIXME Make a comparable! (Or make a separate text cmp version)
+fn rust_array_sort_by_bang(array: &Array, block: extern fn(uint16_t, uint16_t) -> uint8_t) -> Box<Array> {
+ Box::new(array.sort_by(|&a, &b| 0.cmp(&block(a, b)) )) // TODO Ugh!
}
#[no_mangle] pub extern "C"
Binary file not shown.
@@ -10,7 +10,7 @@ module ArrayBackend
attach_function :rust_array_new, [], :pointer
- callback :rust_array_sort_by_bang_callback, [:uint16], :int64
+ callback :rust_array_sort_by_bang_callback, [:uint16, :uint16], :int8
callback :rust_array_reject_callback, [:uint16], :bool
callback :rust_array_each_callback, [:uint16], :void
callback :rust_array_map_callback, [:uint16], :uint16
@@ -142,7 +142,10 @@ def sort_by! &block
return self unless block_given?
return self if size < 2
- @internal_instance = rust_array_sort_by_bang(to_ptr, block)
+ @internal_instance = rust_array_sort_by_bang(to_ptr) do |a, b|
+ p [b, block.call(b), a, block.call(a), block.call(b) <=> block.call(a)]
+ block.call(a) <=> block.call(b)
+ end
self
end
@@ -163,6 +163,11 @@
end
end.to raise_error(RangeError)
end
+ it 'can handle strings' do
+ abc = %w(a b c d e)
+
+ array.sort_by! { |x| abc[x] }.assert == array
+ end
end
describe '#slice!' do
it 'handles an empty array' do

0 comments on commit f4d1f9d

Please sign in to comment.