-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
457cad1
commit 58caab2
Showing
19 changed files
with
376 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use deno_bindgen::deno_bindgen; | ||
|
||
// struct Foo is not "registered" in the inventory, so it `impl Foo` | ||
// is not allowed. | ||
struct Foo; | ||
|
||
#[deno_bindgen] | ||
impl Foo { | ||
#[constructor] | ||
fn new() -> Foo { | ||
Foo | ||
} | ||
} | ||
|
||
fn main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: the trait bound `Foo: BindgenType` is not satisfied | ||
--> tests/compile_fail/impl_registration.rs:8:6 | ||
| | ||
8 | impl Foo { | ||
| ^^^ the trait `BindgenType` is not implemented for `Foo` | ||
| | ||
note: required by a bound in `_assert_impl` | ||
--> tests/compile_fail/impl_registration.rs:7:1 | ||
| | ||
7 | #[deno_bindgen] | ||
| ^^^^^^^^^^^^^^^ required by this bound in `_assert_impl` | ||
= note: this error originates in the attribute macro `deno_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use deno_bindgen::deno_bindgen; | ||
|
||
#[deno_bindgen] | ||
struct Foo; | ||
|
||
#[deno_bindgen] | ||
impl Foo { | ||
#[constructor] | ||
fn new() -> Foo { | ||
Foo | ||
} | ||
} | ||
|
||
#[deno_bindgen] | ||
fn foo(_foo: Foo) {} // Fail | ||
|
||
#[deno_bindgen] | ||
fn foo2(_foo: &mut Foo) {} // Pass | ||
|
||
fn main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0308]: mismatched types | ||
--> tests/compile_fail/struct_by_val.rs:15:8 | ||
| | ||
15 | fn foo(_foo: Foo) {} // Fail | ||
| --- ^^^^ expected `Foo`, found `&mut _` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected struct `Foo` | ||
found mutable reference `&mut _` | ||
note: function defined here | ||
--> tests/compile_fail/struct_by_val.rs:15:4 | ||
| | ||
15 | fn foo(_foo: Foo) {} // Fail | ||
| ^^^ --------- |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use deno_bindgen::deno_bindgen; | ||
|
||
#[deno_bindgen] | ||
struct Input { | ||
a: i32, | ||
b: i32, | ||
} | ||
|
||
#[deno_bindgen] | ||
impl Input { | ||
#[constructor] | ||
fn new(a: i32, b: i32) -> Input { | ||
Input { a, b } | ||
} | ||
|
||
#[constructor] | ||
fn new2() -> Input { | ||
Input { a: 0, b: 0 } | ||
} | ||
} | ||
|
||
fn main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use deno_bindgen_macro::deno_bindgen; | ||
|
||
#[deno_bindgen] | ||
fn add(a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
|
||
#[deno_bindgen] | ||
fn buf_mut(b: &mut [u8]) { | ||
b[0] = 99; | ||
} | ||
|
||
#[deno_bindgen] | ||
fn cstr() -> *const u8 { | ||
b"Hello, World!\0".as_ptr() | ||
} | ||
|
||
#[deno_bindgen] | ||
fn strlen(s: *const u8) -> u32 { | ||
let mut len = 0; | ||
unsafe { | ||
while *s.add(len as usize) != 0 { | ||
len += 1; | ||
} | ||
} | ||
len | ||
} | ||
|
||
#[deno_bindgen(non_blocking)] | ||
fn non_blocking() -> i32 { | ||
42 | ||
} | ||
|
||
#[deno_bindgen] | ||
struct Foo { | ||
internal: i32, | ||
} | ||
|
||
#[deno_bindgen] | ||
impl Foo { | ||
#[constructor] | ||
fn new(internal: i32) -> Foo { | ||
Foo { internal } | ||
} | ||
|
||
fn bar(&self) -> i32 { | ||
42 | ||
} | ||
|
||
fn baz(&self, a: i32) -> i32 { | ||
a | ||
} | ||
|
||
fn qux(&self, a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
|
||
fn quux(&mut self) { | ||
self.internal += 1; | ||
} | ||
} | ||
|
||
fn main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#[test] | ||
fn ui_pass() { | ||
let t = trybuild::TestCases::new(); | ||
t.pass("tests/pass/*.rs"); | ||
} | ||
|
||
#[test] | ||
fn ui_compile_fail() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/compile_fail/*.rs"); | ||
} |
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
Oops, something went wrong.