

Implement 'unimplemented' feature of Rust - Knoldus Blogs
source link: https://blog.knoldus.com/implement-unimplemented-feature-of-rust/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Implement 'unimplemented' feature of Rust
Reading Time: 2 minutes
The headline looks weird. Isn’t it. Well, there are some hidden corals in Rust sea, which you won’t find in Rust documentation. In the continuation of my exploration about Rust language, I found a useful feature unimplemented!
.
This feature lets you write a not-yet-implemented method, like this:
fn doSomething() {
unimplemented!()
}
The methods you define can also take input parameters and specify a return type, like this:
fn fibonacci(n: u32) -> u32 {
unimplemented!()
}
Although your code will compile if you call this method, it will crash with a panic message not yet implemented
.
This is really nice for when you want to stub out some methods as you’re working on a problem. For example, if you are working on an IoT application to control an office door, and you know you’re going to need methods to open and close the door, but you don’t know the details yet. In this case, you can stub out your methods like this:
trait DoorController {
fn open(&self);
fn close(&self);
}
struct MyOffice;
impl DoorController for MyOffice {
fn open(&self) {
unimplemented!()
}
fn close(&self) {
unimplemented!()
}
}
This is helpful when you want to write code using a particular function without having to write the entire implementation. I hope you enjoy reading this blog. Thanks !
Recommend
-
11
Knoldus Blog Audio Reading Time: 3 minutes What are consensus algorithms? Consensus means finding a way so people on a blockchain can reach a common agreeme...
-
7
Don't Worry... I hugged it first Reading Time: 2 minutes Loggers play the most significant role in the software development community that not all developers take it seriously. Due to this, all have lost countle...
-
6
Reading Time: 4 minutes As you all know Rust Programming has Futures which helps to make our code Asynchronous. Rust's Futures are analogous to Promises.This article mainly pertains to the in...
-
17
Knoldus Blogs Reading Time: 3 minutesIn my previous blog, we discussed how Rust performs memory management. Interesting as it is, the concept of ownership d...
-
10
Substrate – A Blockchain Framework on Rust Knoldus Blog Audio Reading Time: 3 minute...
-
9
The Relation between "Rust and Safe Programming" !! Knoldus Blog Audio Reading Time: 5 minutes The Rust
-
5
Lifetime in Rust – Part 1 Reading Time: 4 minutesRust can be a tricky language to work with and one of the prime reasons f...
-
5
Embedded-Rust: Let’s start with STM32F3DISCOVERY Reading Time: 5 minutes An embedded system is computer hardware with soft...
-
6
Working with Loop, While, For Reading Time: 2 minutesI hope you have already been through the following blogs in order to learn control flow and iteration in RUST: Basically, RUST is no different compare...
-
9
Conversation Contributor This c...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK