Skip to content

Commit

Permalink
Implement IntoDartExceptPrimitive for bool (#47)
Browse files Browse the repository at this point in the history
* Update into_dart.rs

* Add tests

* Add comment for #47

* Fix Clippy errors
  • Loading branch information
NightFeather0615 authored Sep 11, 2023
1 parent 57c81a2 commit c4e2bc4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Drop for DartCObject {

/// Exposed only for tests.
#[doc(hidden)]
pub unsafe fn run_destructors(obj: &mut DartCObject) {
pub unsafe fn run_destructors(obj: &DartCObject) {
use DartCObjectType::*;
match obj.ty {
DartExternalTypedData => unsafe {
Expand All @@ -241,7 +241,7 @@ pub unsafe fn run_destructors(obj: &mut DartCObject) {
)
};
for item in items {
run_destructors(&mut **item)
run_destructors(&**item)
}
},
_ => {},
Expand Down
6 changes: 6 additions & 0 deletions src/into_dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ impl IntoDart for bool {
}
}

// https://github.com/sunshine-protocol/allo-isolate/pull/47
//
// Since Dart doesn't have a primitive list implemented for boolean (e.g. `Uint8List` for 8-bit unsigned int),
// we should implement `IntoDartExceptPrimitive` for `bool` so that `Vec<bool>` can be converted to `List<bool>`.
impl IntoDartExceptPrimitive for bool {}

impl IntoDart for String {
fn into_dart(self) -> DartCObject {
let s = CString::new(self).unwrap_or_default();
Expand Down
8 changes: 8 additions & 0 deletions tests/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fn main() {
assert!(!isolate.post(vec![42u64; 100]));
assert!(!isolate.post(vec![42.0f32; 100]));
assert!(!isolate.post(vec![42.0f64; 100]));
assert!(!isolate.post(vec![true; 100]));
assert!(!isolate.post(vec![false; 100]));
assert!(!isolate.post(ZeroCopyBuffer(vec![42i8; 100])));
assert!(!isolate.post(ZeroCopyBuffer(vec![42u8; 100])));
assert!(!isolate.post(ZeroCopyBuffer(vec![42i16; 100])));
Expand All @@ -41,6 +43,8 @@ fn main() {
assert!(!isolate.post([42u64; 100]));
assert!(!isolate.post([42.0f32; 100]));
assert!(!isolate.post([42.0f64; 100]));
assert!(!isolate.post([true; 100]));
assert!(!isolate.post([false; 100]));
assert!(!isolate.post(ZeroCopyBuffer([42i8; 100])));
assert!(!isolate.post(ZeroCopyBuffer([42u8; 100])));
assert!(!isolate.post(ZeroCopyBuffer([42i16; 100])));
Expand Down Expand Up @@ -139,6 +143,8 @@ fn main() {
assert!(isolate.post(vec![42u64; 100]));
assert!(isolate.post(vec![42.0f32; 100]));
assert!(isolate.post(vec![42.0f64; 100]));
assert!(isolate.post(vec![true; 100]));
assert!(isolate.post(vec![false; 100]));
assert!(isolate.post(ZeroCopyBuffer(vec![42i8; 100])));
assert!(isolate.post(ZeroCopyBuffer(vec![42u8; 100])));
assert!(isolate.post(ZeroCopyBuffer(vec![42i16; 100])));
Expand All @@ -160,6 +166,8 @@ fn main() {
assert!(isolate.post([42u64; 100]));
assert!(isolate.post([42.0f32; 100]));
assert!(isolate.post([42.0f64; 100]));
assert!(isolate.post([true; 100]));
assert!(isolate.post([false; 100]));
assert!(isolate.post(ZeroCopyBuffer([42i8; 100])));
assert!(isolate.post(ZeroCopyBuffer([42u8; 100])));
assert!(isolate.post(ZeroCopyBuffer([42i16; 100])));
Expand Down

0 comments on commit c4e2bc4

Please sign in to comment.