Let's dig a bit further into Divyansh Rai's post on Variable & Mutability - https://fifo.im/p/jcjxxyx3ubl0 # Constants Rust also lets you declare constants. So if you read Divyansh's article, you might wonder why we need constant when we have immutable variables? Let me explain...
So constants are different from immutable variables. 1. You can't use `mut` with constant. 2. You must declare variable with `const` keyword & its data type must be specified 3. Constants can be declared anywhere in the scope of the program but they can only be set to a constant value or constant expression, not something that is calculated at run-time.
You might not have got the third point easily. Let me give you an example. The expression below can be computed at compile time so it's a valid expression for Rust ```const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3;``` The variable name `THREE_HOURS_IN_SECONDS` is Rust's naming convention for the constants
Constants are valid within their scope, till the time the entire program runs.
# Shadowing I'll give you a code example to better understand this ```fn main() { let x = 5; let x = x + 1; { let x = x * 2; println!("The value of x in the inner scope is: 12"); } println!("The value of x is: 6"); } ``` Ummmmm 🤨. yeah, that was my reaction. It's just re-assigning with the let keyword
So when I read the use case I won't say pretty much but I was satisfied. So we all agree that we can produce the same scenario by making variables mutable. But what if while re-assigning, the data type is to change midway E.g ``` let spaces = " "; let spaces = spaces.len(); ```
Normally the above expression will throw an error but it won't in this case. That's the benefit of shadowing, it lets you declare the same variable with a different data type
GossipSub: PubSub Extensible Protocol GossipSub is a protocol that extends existing PubSub implementation to make PubSub more efficient. Since GossipSub is an extension of PubSub, it makes sense to know about PubSub before directly jumping on to GossipSub.
FFMPEG & SFTP are such great tools. I'm a fan of them.