You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve realized that we don’t need to manually rewrite all functions from every class as we’re currently doing. By including the RDKit directory in the build.rs file, CXX can automatically find not just the functions in our wrappers, but also those in the RDKit library itself. This can significantly speed up development since we can directly reference the functions in the cxx::bridge.
I’ve created a small example repository to demonstrate how straightforward this is.
As seen in the repository, there are more functions listed in lib.rs than in the wrapper, but all are callable and can be used directly. For example, passing self: &Atom allows us to call functions directly like atom.getTotalValence(). This removes the need for boilerplate code like:
This simplifies usage in the rdkit crate and makes the code more maintainable.
Next Steps
We have two options:
Refactor the existing repo to follow this approach. While it may take some time initially, it will speed up development and reduce potential errors.
Continue building on the example repo I’ve created and start a new crate.
What are your thoughts?
Best regards,
Marco
P.S. I’ve added an explanation on how to download and compile RDKit and link the C++ library to our project. This should also add Windows support (although I haven’t tested it yet).
The text was updated successfully, but these errors were encountered:
mvisani
changed the title
Proposal: Simplify Rust Bindings by Leveraging RDKit's Existing Functions
Proposal: Simplify Rust Bindings
Sep 26, 2024
@xrl I've continued working a bit in this small repo. It actually saves a lot of time ! I'll create a pull request with a couple of modifications in the rdkit-sys crate. I'll wait for your feedback.
Hi @xrl,
I’ve realized that we don’t need to manually rewrite all functions from every class as we’re currently doing. By including the RDKit directory in the
build.rs
file, CXX can automatically find not just the functions in our wrappers, but also those in the RDKit library itself. This can significantly speed up development since we can directly reference the functions in thecxx::bridge
.I’ve created a small example repository to demonstrate how straightforward this is.
Highlights of the Current Wrapper
wrapper.h:
wrapper.cc:
Using RDKit's Built-in Functions
As seen in the repository, there are more functions listed in
lib.rs
than in the wrapper, but all are callable and can be used directly. For example, passingself: &Atom
allows us to call functions directly likeatom.getTotalValence()
. This removes the need for boilerplate code like:This simplifies usage in the
rdkit
crate and makes the code more maintainable.Next Steps
We have two options:
What are your thoughts?
Best regards,
Marco
P.S. I’ve added an explanation on how to download and compile RDKit and link the C++ library to our project. This should also add Windows support (although I haven’t tested it yet).
The text was updated successfully, but these errors were encountered: