Type Normalization
THAT is SO NICE! I was wondering all the time how often these scenarios actually might happen and since I have tackled some other problem in the meantime I will not spend any more effort on this.
My idea for the platform-specific types long
and unsigned long
would be to cast to 32bit types. This should not cast down (as far as I can tell) but stay identical or cast to 64bit when converting to C++
input and not make any problems. The C++
functions would still use the native type.
Generics
I understand now. I think for now I will focus on function signatures which use the class templates as input/output. I do not plan to support the usage of the generics themselves within Rust for my first version of vtk-rs
.
vtkVector<double, 3> GetPosition();
void SetPosition(vtkVector<double, 3> &position)
I will then have to create conversions between vtkVector<T, N>
and my chosen Rust equivalent. In this case, I would probably opt for the array type [T; N]
. In this way, I can expose the function without having to deal with the class template vtkVector<T, N>
explicitly.
In total, this means of course that all functionality which might be provided by vtkVector<T, N>
is lost and not directly exposed within the crate.
Future Plans
This in particular would be very useful for the next steps in exposing the templates themselves. I see two (partially distinct) ways forward in exposing them.
1. Expose only what is used by VTK.
This would be a good starting point and very reasonable to tackle as a next step.
Although it might already be too much to be covered by a finite amount of cases. Assume a function which takes a generic.
template<class N> void TakeGeneric(vtkVector<double, N>);
If we wanted to expose this functionality exhaustively, we would have to write bindings for each possible case.
void TakeGeneric_0(vtkVector<double, 0>);
void TakeGeneric_1(vtkVector<double, 1>);
...
I do not know if VTK uses any public template functions. But certainly, constructors of these classes would qualify.
2. Provide Macros to generate Bindings for Templated Classes
This attempt is very, very intricate and will probably require lots of work. Since Rust is compiled and has a preprocessor, it is in principle possible to recreated the templating approach of C++
. I do not know if any dedicated crates exist to handle this functionality. But in principle (although practise might be very hard) it might be possible to provide a Rust proc-macro which scans Rust code and generates appropriate C++
code which can then be linked together.
However, this is very difficult and not straightforward at all and I will probably never go down this path at all.