[Rust Daily] 2023-10-02 Improve the auto-complete function in Rust macros

Improved autocomplete functionality in Rust macros

Autocomplete is a feature provided by the IDE that can help developers quickly find the correct keywords and parameters when writing code. In Rust macros, autocomplete may appear inaccurate or incomplete.

The author of the article introduces the following methods to improve the auto-complete function in Rust macros, so that you can have a better experience when using your macros.

Original link https://blog.emi0x7d1.dev/improving-autocompletion-in-your-rust-macros/

IoT and Rust: Connecting to wifi on ESP

This article is the first in a new series on Internet of Things (IoT) development on the ESP32 using Rust. This series of articles will focus on several IoT hardware and cloud connectivity aspects, such as WiFi and HTTP.

For most IoT services, the first step is always to obtain some kind of network access. So, in this post, we'll kick off the series by configuring and setting up WiFi, which we'll do using the esp-idf-svc crate.

Original link https://dev.to/apollolabsbin/iot-with-rust-on-esp-connecting-wifi-4be6

Two dynamic dispatch methods in Rust and C++

Both Rust and C++ have dynamic dispatch built-in (but implement it differently), and this video introduces both languages' approaches and weighs their pros and cons.

Dynamic dispatch is a runtime feature that allows the correct function to be called at runtime, not just compile time. This is crucial for achieving polymorphism, an important concept in programming that allows you to write code that can handle different types of data.

Rust uses a mechanism called a trait object to implement dynamic dispatch. A trait object is a pointer to any type that implements the given trait. When you call a method on a trait object, the compiler looks for the correct function to call at runtime.

C++ uses a mechanism called a virtual method table (vtable) to implement dynamic dispatch. vtable is an array of pointers to all virtual functions of the object. When you call a virtual method on an object, the compiler looks in the vtable for the correct function to call.

Advantages and Disadvantages of Dynamic Dispatch in Rust and C++

Rust

advantage:

  • Trait objects are type-safe, which means the compiler can ensure that you don't call methods on incompatible types.

  • Trait objects have very little performance overhead.

shortcoming:

  • The use of trait objects can make code harder to read and understand.

C++

advantage:

  • The use of virtual method tables can make the code easier to read and understand.

shortcoming:

  • Virtual method tables may cause additional performance overhead.

  • The use of virtual method tables can lead to further errors, such as virtual methods not being overridden correctly or virtual destructors not being implemented correctly.

YouTube video https://www.youtube.com/watch?v=wU8hQvU8aKM

--

From Daily Team BobQ, FBI Newbie

Community learning exchange platform subscription:

  • Rustcc Forum: support rss

  • WeChat public account: Rust language Chinese community

Guess you like

Origin blog.csdn.net/u012067469/article/details/133532864