·2 min read

Only rust concepts you need to learn Solana

Introduction

A common misconception while learning Solana is that you need to get familiar with 100% of Rust concepts and let's be frank no one knows 100% of Rust, I saw a post on X recently where founder of C++ told he dont know everything about C++ he have to look too

Lets get straight to the point

Even if you know you want to develop on a blockchain that Uses rust (NEAR, Solana, Elrond) you dont need to learn everything on Rust.

Luckily, The Rust concepts used by blockchain is very small, as per me it would be around 20-30% of rust which is actually used by blockchains. and about 10-15% is used very heavily. So if we nail that 10-15% we can create solana programs comfortably

NOTE: This applies to programs, if you are building or contributing to the blockchain client you need to be more fluent with rust

I assume anyone reading this blog is familiar with anchor if not please at least get familiar with it, get to the point where you know what the file does and how it works command like anchor init, anchor build and so back and so forth

lets create a anchor project name it learnrust

Conditional statements

There are 2 types of conditional statement

  • If-Else statements
  • Ternary operator

lets take a function call greet_day in your lib.rs

rust
pub fn greet(ctx: Context<Initialize>, time: u64) -> Result<()> {
    if time >= 12 {
        msg!("It's afternoon");
    } else if time >= 18 {
        msg!("It's evening");
    } else {
        msg!("It's morning");
    }
    Ok(())
}