Commit Graph

63 Commits

Author SHA1 Message Date
David Tolnay
1bcc9fe2e5
Test returning opaque types in CxxVector from C to Rust 2020-04-25 18:02:17 -07:00
David Tolnay
9b304204b7
Use more appropriate name for vector arguments in tests 2020-04-25 18:02:17 -07:00
David Tolnay
c87c215f56
Add begin/end iterators to rust::Vec 2020-04-25 18:02:15 -07:00
David Tolnay
e1dcdf7317
Parse vector's type as CxxVector 2020-04-25 18:02:13 -07:00
David Tolnay
c01d0a0f84
Rename CxxVector::size to len to match Rust conventions 2020-04-25 18:02:10 -07:00
David Tolnay
85db5a01b2
Touch up PR 67 2020-04-25 18:02:08 -07:00
David Tolnay
d1413040ae
Remove absolute paths in non-generated code 2020-04-25 18:02:07 -07:00
David Tolnay
4f6dd4e631
Simplify vector tests using UniquePtr deref 2020-04-25 18:02:07 -07:00
David Tolnay
507c2d75cf
Merge pull request #67 from myronahn/master
C++ std::vector<T> and Rust std::vec::Vec<T> support
2020-04-25 18:01:54 -07:00
David Tolnay
7c29546739
Revert some unrelated changes from PR 67 2020-04-25 13:13:43 -07:00
David Tolnay
37dd7e1174
Format with clang-format 2020-04-25 12:51:59 -07:00
Myron Ahn
eba35cfce7
C++ std::vector<T> and Rust std::vec::Vec<T> support
Add basic std::vector and std::vec::Vec support across FFI boundary.
2020-04-25 12:47:04 -07:00
David Tolnay
1044d44f30
Suppress irrelevant "required by this bound" from error message 2020-04-22 20:01:21 -07:00
David Tolnay
4b07ab92e3
Improve span of unsized opaque type error 2020-04-22 19:50:21 -07:00
David Tolnay
ab73957a4e
Add ui test for unnamed receiver type error message 2020-04-22 18:25:43 -07:00
David Tolnay
2dd73eaf03
Add ui test for reserved type names 2020-04-22 17:56:27 -07:00
David Tolnay
7a03847db2
Add ui test for unrecognized receiver type 2020-04-22 16:54:34 -07:00
David Tolnay
6d9f4aab20
Add ui test for disallowed lifetimes 2020-04-22 16:39:44 -07:00
Joel Galenson
e1e969d06f Allow &self without a type when the block only has one type 2020-04-22 08:44:49 -07:00
David Tolnay
5e29b217c3
Rely on UniquePtr Deref impl in tests 2020-04-17 16:44:03 -07:00
Joel Galenson
c1c4e7ac6b Support calling Rust methods from C++
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
  fn get(self: &R) -> usize;
  fn set(self: &mut R, n: usize);
This syntax requires Rust 1.43.
2020-04-16 16:25:04 -07:00
Joel Galenson
3d4f612b34 Support calling C++ methods from Rust
These methods can be declared in the bridge by naming the first
argument self and making it a reference to the containing class, e.g.,
  fn get(self: &C) -> usize;
  fn set(self: &mut C, n: usize);
This syntax requires Rust 1.43.

Note that the implementation also changes the internal naming of shim
functions so that they also contain the name of the owning class, if
any.  This allows defining multiple methods with the same name on
different objects.
2020-04-16 16:24:48 -07:00
David Tolnay
633b1f5f1f
Switch C-style casting to reinterpret_casts 2020-04-14 16:42:06 -07:00
David Tolnay
efe81052e7
Touch up &[u8] PR 2020-04-14 16:42:06 -07:00
David Tolnay
eb952bac14
Format with rustfmt and clang-format 2020-04-14 16:42:06 -07:00
Adrian Taylor
ec9430e657 Adding missing tests; fixing typo. 2020-04-14 16:12:21 -07:00
Adrian Taylor
f5dd552036 Adding &[u8] support.
This change adds specifically, support for &[u8] with a corresponding
rust::Slice<uint8_t> type. No other types of slice are permitted. The
rationale is that it may be common to pass binary data back and forth
across the FFI boundary, so it's more urgent to get this in place sooner.
Broader support for other slices can wait for the future.

But, both C++ and Rust-side bindings should allow the existing support
to be broadened to other Slice types in future without code changes.

A few specific notes:

* The name "rust::Slice" might be better as "rust::SliceRef" but I'm
  following the precedent of "rust::Str".
* It would be good to add constructors from std::span but as that's
  a C++20 feature, that may have to wait until C++ feature detection
  is resolved.
* Internally, this follows the pattern of &str, where the parser will
  initially recognize this as Type::Ref (of Type::Slice) but then
  will replace that with Type::SliceRefU8. Type::Slice should not
  persist through later stages. As we later come to support other
  types of slice, we would probably want to remove Type::SliceRefU8.
2020-04-14 14:13:48 -07:00
David Tolnay
b5609f86ca
Add UniquePtr test 2020-04-09 23:44:23 -07:00
David Tolnay
a95b2341d0
Suppress clippy::ptr_arg triggering on &String in tests 2020-04-09 23:26:16 -07:00
David Tolnay
75dca2e846
Passing function pointer from Rust to C++ 2020-03-29 21:50:25 -07:00
David Tolnay
9964262630
Implement and test some more fallible return types 2020-03-25 16:44:11 -07:00
David Tolnay
42ebfa2d5e
Add some PartialEq impls for CxxString 2020-03-25 12:26:22 -07:00
David Tolnay
f90ce8585b
Remove trailing whitespace from tests from PR 83 2020-03-25 12:15:18 -07:00
Myron Ahn
8484930071 Result now works for UniquePtr and other types 2020-03-25 22:39:00 +07:00
David Tolnay
09462acd4b
Disallow shared structs having 0 fields 2020-03-20 14:58:56 -07:00
David Tolnay
265f6a079d
Suppress some clippy lints in test suite 2020-03-18 20:14:00 -07:00
David Tolnay
1a2683ac22
Allow .rs.h extension when including generated header 2020-03-17 19:13:22 -07:00
David Tolnay
bffcdd5f4b
Use consistent filenames for generated code
This makes it clearer that the filename doesn't need to be connected to
the rule name.
2020-03-17 19:12:38 -07:00
David Tolnay
ebef4a23a2
Implement fallible C++ functions 2020-03-17 17:34:52 -07:00
David Tolnay
cecada6d38
Fix fallible void return 2020-03-17 01:46:07 -07:00
David Tolnay
b6c5ea7233
Add Rust fallible test functions 2020-03-17 00:15:48 -07:00
David Tolnay
736cbcad40
Move header include path to rust/cxx.h 2020-03-11 16:51:38 -07:00
David Tolnay
85db248625
Test returning unique_ptr<string> from Rust to C++ 2020-03-06 16:26:46 -08:00
David Tolnay
2fe58c670c
Declare test suite helpers noexcept 2020-03-06 16:23:09 -08:00
David Tolnay
4b3a66edf1
Implement returning unique_ptr from Rust to C++ 2020-03-06 16:22:14 -08:00
David Tolnay
5cd8d61f9d
Implement returning Box from Rust to C++ 2020-03-06 16:18:44 -08:00
David Tolnay
a7d00e8281
Test &R passed from Rust to C++ 2020-03-06 15:53:33 -08:00
David Tolnay
be13d8ad2c
Test Box returned from C++ to Rust 2020-03-06 15:50:24 -08:00
David Tolnay
40226ab58a
Implement passing ownership of string to Rust 2020-03-03 00:05:35 -08:00
David Tolnay
750755e557
Rename namespace to rust::inline cxxbridge01 2020-03-01 13:47:29 -08:00