Wednesday, May 4, 2022

Rust bare metal programming

If you are a Rust enthusiast and looking for something to read and try. I would recommend https://os.phil-opp.com/minimal-rust-kernel 

The blogs explains how to build OS in rust.

You can have a start over and build OS if you missed to build it in your college days . Blog starts from OS bigbang with a compiler story telling way. A basic understanding of Rust would be a prerequisite , but the blog explains the builing steps in Rust compiler driven programming method. So it would be good learning experience in embedded Rust programming .

Friday, April 15, 2022

Type-Driven API Design in Rust by Will Crichton

I think that below video is one of the must seen video before reading any source code in Rust language. I was confused with this Trait futures::future::FutureExt when I read through some of the async programs. It is very common that people extending the traits and types in Rust. The "ext" traits were very hard to digest for me.

After seeing this video, these APIs makes more sense.



.

Saturday, March 19, 2022

Rust- Generic type T is super set of &T and &mut T

T includes both & T and &mut T

I had a misconception in Rustlang that the generic types &T and &mut T are  not subset of generic type  T. It turned out to be totally wrong.  Generic Type T includes both &T and &mut T. It is quite easy to get believed that  &T and &mut T are not part of T .

but actually it is as below






I think below is the proper definition of reference types in Rust - &mut T - is the exclusive reference to the value and &T is the shared reference to the value.

When you have exclusive reference(&mut T)  to a value, you can mutate it and guarantees no other references for it at that point of time.


Example:




In the example program the function 'print' has type with trait debug and it is a generic type T.
We are able to pass the &v, &mut v and v to the print function. Meaning the  type check  T  is able to accept the  exclusive reference and shared references.


Reference: