Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the ability to write typemaps #173

Closed
Dushistov opened this issue Apr 27, 2019 · 1 comment
Closed

Simplify the ability to write typemaps #173

Dushistov opened this issue Apr 27, 2019 · 1 comment
Assignees
Milestone

Comments

@Dushistov
Copy link
Owner

Dushistov commented Apr 27, 2019

The new syntax should be similar to code below.

This should help to resolve several issues:

  1. add Rust(std::option::Option) <-> Java(X) mapping #11 at now it is impossible to handle conversation of Option<T> and Option<&T> at once,
    because of Rust trait doesn't allow this, see rust Spurious "downstream crates may implement trait ..." rust-lang/rust#50238 and Spurious "note: downstream crates may implement trait Foo for type &_" rust-lang/rust#48869
  2. Passing repr(C) struct by value #167 should simplify transfer of #[repr(C)] between C++<->Rust
  3. Support Option as value of Result? #133 It would be possible in user's Rust code write how to handle Result<Option<
foreign_typemap!(
    define_c_type!(
	#[repr(C)]
	struct concat_ident!(CFnOnce, swig_c_type!(T)) {
	    cb: extern "C" fn(swig_c_type!(T), *mut c_void),
	    ctx: *mut c_void,
	})
        
    (rust, <T, F: FnOnce(T)> $r_param: F) <= concat_ident!(CFnOnce, swig_c_type!(T))
    {
	  |x| $c_param.cb(convert_to_c!(x), $c_param.ctx)
    }

     define_helper_f_helper!(
	 void concat_ident!(result_ready, swig_c_type!(T))(swig_c_type!(T) ret, void *ctx)
	 {
	     swig_f_type!(T) cpp_ret = convert_to_f!(ret);
	     auto ptr = std::make_shared<swig_f_type!(T)>(std::move(cpp_ret));
	     auto fi =
		 static_cast<QFutureInterface<std::shared_ptr<swig_f_type!(T)>> *>(ctx);
	     fi->reportResult(std::move(ptr));
	     fi->reportFinished();
             delete fi;
	 }
     )
    (f, input_to_output) => r#"QFuture<std::shared_ptr<swig_f_type!(T)>>"# r#"
        auto fi = new QFutureInterface<std::shared_ptr<swig_f_type!(T)>>;
       concat_ident!(CFnOnce, swig_c_type!(T)) cb;
       cb.cb = concat_ident!(result_ready, swig_c_type!(T));
       cb.ctx = fi;
       $f_result = fi->future();
       $c_result = cb;
 }"#
);


foreign_typemap!(
    (rust, &str) => RustStrView {
        RustStrView::from_str($r_param)
    }
    (f) => QString r#"
$f_result = QString::fromUtf8($c_result.data, $c_result.len);
"#);

Missed features:

  1. Temporary variables in rules
  2. Combining generic rules with $out
  3. Optimization
@Dushistov Dushistov added this to the 0.4.0 milestone Apr 27, 2019
@Dushistov Dushistov self-assigned this Apr 27, 2019
@Dushistov
Copy link
Owner Author

Combining generic rules with $out

This is only missed. it will be addressed if someone need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant