Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1833
Abstract
/8b1dd003c24465d41ad13a5a1e951c66.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="3b7d"><code>Self</code> in method arguments is <i>syntactic sugar</i> for the receiving type of the method, that is, the type whose <code>impl</code> this method is in, and in this case, UIit is <code>Inputs</code>. You could replace Self with <code>Inputs</code> and the code would work fine.</p><p id="6188">Remember <code>#[generate_interface]</code> originates from the <a href="https://crates.io/crates/rifgen"><co<b>de>rifgen</co<b></a> crate as described in the <a href="https://blog.devgenius.io/integrating-rust-with-android-development-ef341c2f9cca">first part of the series</a>.</p><p id="c9c8">Now let us implement the U.I.</p><h2 id="f210">Designing the U.I. 📱</h2><p id="d49a">As described earlier, the U.I. would have 2 input text fields and 3 output text fields. It would be a simple layout to illustrate:</p>
<figure id="a424">
<div>
<div>
<iframe class="gist-iframe" src="/gist/Kofituo/2f0cb830eb039744b3e67e61298f5c83.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="8508">And that’s it! This is what the application should <a href="https://github.com/Kofituo/RustApplication/blob/main/app/src/main/java/com/example/rustapplication/Illustration.jpg"><b>look like</b></a>. Here’s a gif of it</p>
<figure id="73bf">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=http
Options
s%3A%2F%2Fgfycat.com%2Fifr%2Ffeistyvaluablechinesecrocodilelizard&display_name=Gfycat&url=https%3A%2F%2Fgfycat.com%2Ffeistyvaluablechinesecrocodilelizard&image=https%3A%2F%2Fthumbs.gfycat.com%2FFeistyValuableChinesecrocodilelizard-size_restricted.gif&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=gfycat" allowfullscreen="" frameborder="0" height="546" width="246">
</div>
</div>
</figure></iframe></div></div></figure><p id="4b8f">Whenever the user taps the ‘equal to’ button, the numbers from the text boxes are passed to the struct written in <code>Rust</code>. The values are then computed and the result is displayed in the textbox. Feel free to modify the code and try out other ways of adding some <code>Rust</code> variety to your Android project.</p><h2 id="34c1">Next Steps 👣</h2><p id="3092"><b>If you faced any problems while trying this walkthrough or have any questions, feel free to reach me via email at [email protected]!</b></p><h2 id="be42">Support</h2><p id="b5d3">If you’ve enjoyed this series and would like to show gratitude, you can support the author through <a href="https://bmc.link/otuokofi"><b>Buy Me A Coffee</b></a><b>.</b></p><h2 id="3b92">Further Reading 📖</h2><p id="78b7">Learn more about the dependencies used in this walkthrough:</p><ul><li><a href="https://github.com/Dushistov/flapigen-rs"><b>Dushistov/flapigen-rs: Tool for connecting programs or libraries written in Rust with other languages</b></a></li><li><a href="https://github.com/Kofituo/rifgen"><b>Kofituo/rifgen:Program for translating libraries written in Rust to interface files. It works with flapigen</b></a></li><li><a href="https://github.com/sfackler/rust-jni-sys"><b>sfackler/rust-jni-sys</b></a></li></ul><h2 id="d4d6">Repository</h2></article></body>