Commit Graph

642 Commits

Author SHA1 Message Date
David Tolnay
e68634c0a1
Fix missing newline after cxxbridge02$exception declaration 2020-03-18 12:03:40 -07:00
David Tolnay
047223384e
Make trycatch sfinae work on msvc 2020-03-18 11:35:39 -07:00
David Tolnay
3e3e0af976
Allow catch behavior to be customized
If the user's cxx::bridge invocation includes any header that defines
the following function, they get it's behavior as the exception-to-Result
conversion.

    namespace rust::behavior {
    template <typename Try, typename Fail>
    static void trycatch(Try &&func, Fail &&fail) noexcept try {
      func();
    } catch (/* up to you */) {
      fail(/* const char *msg */);
    }
    }

The default behavior is equivalent to:

    } catch (const std::exception &e) {
      fail(e.what());
    }

Codebases that use Folly, for example, may be interested in behavior
like this instead for better type information on the error messages:

    } catch (const std::exception &e) {
      fail(folly::exceptionStr(e));
    } catch (...) {
      fail("<unknown exception>");
    }
2020-03-17 23:03:24 -07:00
David Tolnay
82c1617925
Catch block isn't allowed to throw 2020-03-17 22:54:12 -07:00
David Tolnay
5d12144989
Factor catch implementation to static function 2020-03-17 22:22:24 -07:00
David Tolnay
4791f1c115
Include <utility> when using std::move 2020-03-17 21:55:19 -07:00
David Tolnay
3577d451d7
Fix blank first line if no headers emitted 2020-03-17 21:48:13 -07:00
David Tolnay
b7a7cb6785
Provide more struct definitions where needed 2020-03-17 21:40:47 -07:00
David Tolnay
26ad0bd98c
Look for end of line when finding headers ifdefs 2020-03-17 21:34:16 -07:00
David Tolnay
ebef4a23a2
Implement fallible C++ functions 2020-03-17 17:34:52 -07:00
David Tolnay
1e548174c3
Implement fallible Rust functions 2020-03-17 00:15:48 -07:00
David Tolnay
277e3ccdba
Factor out C++ indirect return predicate 2020-03-17 00:11:01 -07:00
David Tolnay
2fb14e934b
Add Type::Void variant
Not currently usable as a function argument or explicit return value,
but will be required when we introduce Result for the case of fallible
void functions, whose return type will be Result<()>.
2020-03-15 23:11:40 -07:00
David Tolnay
8c7304998e
Bump inline namespace to match minor version 2020-03-13 01:29:23 -07:00
David Tolnay
3383ae719f
Add f32 and f64 types 2020-03-13 01:14:11 -07:00
David Tolnay
736cbcad40
Move header include path to rust/cxx.h 2020-03-11 16:51:38 -07: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
09011c304b
Fix alignment of by-value returns from Rust 2020-03-06 14:46:46 -08:00
David Tolnay
f51447e2b9
Implement moving ownership of struct arguments to Rust 2020-03-06 14:22:00 -08:00
David Tolnay
33169bdd59
Safe to assume more about the Box representation
https://doc.rust-lang.org/std/boxed/index.html:
So long as T: Sized, a Box<T> is guaranteed to be represented as a
single pointer and is also ABI-compatible with C pointers (i.e. the C
type T*).
2020-03-06 13:10:58 -08:00
David Tolnay
9c68b1a0c6
Lazily compute include set 2020-03-06 11:27:29 -08:00
David Tolnay
cc3767f0ed
Format with rustfmt 2019-10-07 2020-03-06 10:42:02 -08:00
David Tolnay
a46a237fe7
Make passing String by value to C++ const 2020-03-06 10:28:15 -08:00
David Tolnay
f6292378c7
Add rust::Box member type aliases 2020-03-01 21:09:11 -08:00
David Tolnay
baae443ae2
Change Str to Repr operator to explicit 2020-03-01 20:20:10 -08:00
David Tolnay
9081beb1a0
Remove redundant prefix from mangled Box related symbols 2020-03-01 19:52:09 -08:00
David Tolnay
9ad1fbc478
Pass ending comment to end_block
Clang-format doesn't always like the same ending comment as the start of
the block. In particular it wants:

    inline namespace cxxbridge01 {
      ...
    } // namespace cxxbridge01
2020-03-01 14:05:01 -08:00
David Tolnay
750755e557
Rename namespace to rust::inline cxxbridge01 2020-03-01 13:47:29 -08:00
David Tolnay
324437a263
Rename C++ RustBox to Box 2020-03-01 13:47:29 -08:00
David Tolnay
09dbe75a5d
Rename C++ RustStr to Str 2020-03-01 13:47:28 -08:00
David Tolnay
5608216979
Rename C++ RustString to String 2020-03-01 13:47:28 -08:00
David Tolnay
b92e66f4dc
Support nested blocks in C++ emitter 2020-03-01 13:37:15 -08:00
David Tolnay
7e219b8099
Use absolute qualified identifiers in generated C++
This avoids collision with the user's namespaces having the same name.

Less important in the context of the current names right now, but more
important after we move our public C++ API from cxxbridge:: to rust::.
In fact our example code already uses org::rust:: as the namespace,
inside of which a non-absolute rust:: would cause trouble.
2020-03-01 13:14:55 -08:00
David Tolnay
2a1eaac049
Accept non-\n line endings
On Windows, include_str brings in cxxbridge.h with \r\n line endings.
2020-02-24 02:02:58 -08:00
David Tolnay
7eb9c6b2a0
Touch up cxxbridge.h emit PR 2020-01-27 22:35:59 -08:00
RS
0a2d117fba Emit cxxbridge (#27)
* Working cxxbridge output.

* Add a way to emit cxxbridge.h
2020-01-27 21:47:37 -08:00
David Tolnay
4a44122b0f
Resolve Wreturn-type-c-linkage warnings 2020-01-25 16:26:54 -08:00
David Tolnay
8861bee797
Support opaque types that are not structs 2020-01-20 18:40:16 -08:00
David Tolnay
17955e2e8c
Implement special case types in extern Rust argument position 2020-01-20 18:09:41 -08:00
David Tolnay
e43b737f2c
Release 0.1.0 2020-01-08 08:57:24 -08:00
David Tolnay
7db7369797
Safe FFI between Rust and C++ 2020-01-08 08:57:24 -08:00