Going over ownership in the #LearnRust book again and it makes so much more sense this time around.
π¦ #RustQuiz
What is the output of this?
A. Error
B. RustJsPython
C. (Rust, Js, Python)
D. Rust
(Not hard/tricky or unique as #RustChallenge, just simple quizzes)
#rustquiz #RustChallenge #rustlang #rust #rusttips #learnrust
β¨ Rust Challenge explained
Ans:
2. A gives output and B gives error
In `A` code:
π x will be assigned to i8 type since we are using i8 to compare in assert_eq.
π x.pow(6) will be 2 power 6 which is 64, it will work perfectly
In `B` code:
π x will be assigned default to i32
π But in second line you will get ambiguity error π€―
π And compiler will ask to specify the type for x explicitly
#rustlang #learnrust #rusttips #rust
π¦ Fix the following code
πͺ² Error: "cannot borrow `x` as mutable because it is also borrowed as immutable"
Playground link:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b13fc771b4c2ea39d490375c54fd5a4d
π You can answer either with fixed playground link or just explanation (No poll)
#RustChallenge #rustlang #rust #learnrust
β¨ Yes, the answer is C
It prints:
-10
+100
π― What is the use of `+` in format string?
π By default, number sign is not printed for positive numbers
π We use `+` to print sign also
print!("{:+} {:+}", 1, -2);
It will print
+1 -2
#rustlang #rusttips #rust #learnrust
π¦ Format String tricks - Minimum width
π You can set minimum width for the characters that gets printed
Eg:
{var_name:min_width}
π Helps to ensure that fields in the output are of a uniform width
#rustlang #rusttips #rust #learnrust
β¨ Using variable inside Format String
π It appears many people are not aware of this syntax that was introduced in Rust 1.58(2022/01/13)
π You can also use format specifiers along with it
#rustlang #rusttips #rust #learnrust #programming
Hot take: learning rust is easy, I learnt it in one day by sitting down and just coding for hours at a time. I know I prb learned way less than half the language but at least I'm to the point where I can write a semi complex program which implements structs, traits, functions and implementation blocks etc. #rust #developer #learnrust #foss
#rust #developer #learnrust #foss
π’New in MEAPπ’
Want to level up your programming skills and learn Rust?
Learn Rust in a Month of Lunches by @Mithridates, will teach you to build real software, understand messages from the compiler and Clippy, make informed decisions on types, work with external crates, and even write your own macros.
Transform yourself into a Rustacean in 22 short lessons: http://mng.bz/Q84w
Get 45% off with code mlmacleod till Feb 3.
#rustlang #learnrust #rustacean #rust
Are you a #curious person who constantly questions the status quo?
Do you prefer #quality over quantity?
Do you value technical excellence?
Do you want to empower others to become their best selfes?
Do you value an inclusive and friendly community?
Then join us #Rustacean's on the exhilarating ride that is learning #Rust!
(and if you like crabs π :ferris: π‘ )
#learn #learnrust #learning #inspiration #rustlang #Rust #rustacean #quality #curious
I solved the second part of day 3 challenge in #Rust using a generic function - ridiculously hard to get the types right that it compiles, but I think I understand the gist of it.
#adventofcode #learnrust #rust
Wait, is this...a Ferris wheel!? :awesome:
π‘
Do you know what that means?
It means you should go along for the beautiful and exhilarating ride that learning #Rust is.
And Ferris, the crab, will always be on your side, so you have no reason to panic!. :ferris: π
#LearnRust #Ferris RustLang #FerrisWheel #Emoji
#emoji #ferriswheel #ferris #learnrust #Rust
I just completed "Calorie Counting" - Day 1 - Advent of Code 2022 #AdventOfCode https://adventofcode.com/2022/day/1
Yes, I know. It took a long time to do both parts. But hey, great opportunity to #LearnRust.
Criticisms welcome:
https://codeberg.org/ashwinvis/advent-of-code/src/branch/main/2022/src/day1.rs
#AdventOfCode2022 #rust #learnrust #adventofcode
Once again, trying to pick up #Rust via solving #AdventOfCode puzzles. I understand most of the things now, but it is still taking time to implement the algorithm I have in mind.
One thing I don't get is why a few methods return a Some / None option and others return a Ok / Err objects. Why do we have two such constructs? Aren't they similar?
#AdventOfCode2022 #learnrust #adventofcode #rust