Remove TryFn since throwing fn ptr are not implemented yet

This commit is contained in:
David Tolnay 2020-11-29 19:41:33 -08:00
parent e468f05d8f
commit f031c32dca
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 11 additions and 16 deletions

View File

@ -1128,7 +1128,7 @@ fn write_type(out: &mut OutFile, ty: &Type) {
write!(out, ">");
}
Type::Fn(f) => {
write!(out, "::rust::{}<", if f.throws { "TryFn" } else { "Fn" });
write!(out, "::rust::Fn<");
match &f.ret {
Some(ret) => write_type(out, ret),
None => write!(out, "void"),

View File

@ -294,22 +294,19 @@ private:
#ifndef CXXBRIDGE1_RUST_FN
// https://cxx.rs/binding/fn.html
template <typename Signature, bool Throws = false>
template <typename Signature>
class Fn;
template <typename Ret, typename... Args, bool Throws>
class Fn<Ret(Args...), Throws> final {
template <typename Ret, typename... Args>
class Fn<Ret(Args...)> final {
public:
Ret operator()(Args... args) const noexcept(!Throws);
Ret operator()(Args... args) const noexcept;
Fn operator*() const noexcept;
private:
Ret (*trampoline)(Args..., void *fn) noexcept(!Throws);
Ret (*trampoline)(Args..., void *fn) noexcept;
void *fn;
};
template <typename Signature>
using TryFn = Fn<Signature, true>;
#endif // CXXBRIDGE1_RUST_FN
#ifndef CXXBRIDGE1_RUST_ERROR
@ -388,10 +385,8 @@ using box = Box<T>;
template <typename T>
using vec = Vec<T>;
using error = Error;
template <typename Signature, bool Throws = false>
using fn = Fn<Signature, Throws>;
template <typename Signature>
using try_fn = TryFn<Signature>;
using fn = Fn<Signature>;
template <typename T>
using is_relocatable = IsRelocatable<T>;
@ -408,13 +403,13 @@ void panic [[noreturn]] (const char *msg);
#ifndef CXXBRIDGE1_RUST_FN
#define CXXBRIDGE1_RUST_FN
template <typename Ret, typename... Args, bool Throws>
Ret Fn<Ret(Args...), Throws>::operator()(Args... args) const noexcept(!Throws) {
template <typename Ret, typename... Args>
Ret Fn<Ret(Args...)>::operator()(Args... args) const noexcept {
return (*this->trampoline)(std::move(args)..., this->fn);
}
template <typename Ret, typename... Args, bool Throws>
Fn<Ret(Args...), Throws> Fn<Ret(Args...), Throws>::operator*() const noexcept {
template <typename Ret, typename... Args>
Fn<Ret(Args...)> Fn<Ret(Args...)>::operator*() const noexcept {
return *this;
}
#endif // CXXBRIDGE1_RUST_FN