Yeah, Rust is brutal when you have lists.
The problem: you get a list, return second half of it. I decided to solve it without using Clone.
Clone
I believe I just found a very idiomatic way to create a single-elemented collection (like HashSet, Vec, VecDeque, etc).
… actually, not a single-elemented. Any fixed number of elements.
I found my own way to learn Rust. After initial ‘impossible’ wall, there is other kind of problem, when you stuck in the middle of an expression and can’t make value to be of a suitable type.
I got myself into simple problem: to split string into pieces by space. During this …ehem… problem I found I need to filter empty splits if there is more than one space in row.
My intial code was:
foo.split("…
foo.split("
Let’s talk about two dimensional matrices in Rust. To be precise, two-dimensional matrices written as nested arrays.
A simple 2x2 matrix is looks like this:
let matrix = [[1, 2], [3, 4]];
I’ve just solved a problem at Leetcode with following signature:
pub fn num_islands(grid: Vec<Vec<char>>) -> i32
When I solved it I changed it to:
pub fn num_islands(mut grid: Vec<Vec<char>>) -> i32 {
I got to a next leetcode crossword. Even before I got to the core of the problem I was puzzled with…
Every language starts with a playground. You CAN do amazing things there, but they are as amazing as a neighboring kid sand cake.
As soon as you move from playground into ‘do something real’ you move from sand cake realm into ‘paper applications with a…
Rehearsal of the things I learned. If you are learning yourself, I advise you to go for the…
I’m doing leetcode exercises at leisure pace, as one would do a moderately complex puzzles in a game.
Some are good, some are ‘too mathy’ (solution is trivial, but need to be calculated, almost by hands). And, finally, I got to the proper task…
I found a problem with chars iterator for Sting. next() function returns Option<char> (owned chars), and adding .peekable() to iterator gives .peek() function which returns Option<&char>. Which is a great inconvenience if you try to work with those two types without unwrapping them. You can’t…
chars
next()
Option<char>
.peekable()
.peek()
Option<&char>
Zip iterator can return pairs from two iterators, but it stops at the end of the shortest iterator. There is itertools zip_longest, but if you don’t have access to external library and knows the size of your iterators, there is a really neat trick to…
I’ve just found a peculiar edge case for scopes in Rust.
Consider this code:
let l = list;
while let Some((val, l)) = l.step(){ output.push(val);}
No, not that newtype.
I’ve started next chapter of my Rust study, which is, ‘write your own list’. If you don’t know, writing list in Rust is really challenging, because Rust do not permit corner-cutting. Lists are at least 50% pointers, and the…
It’s big, it’s confusing and it’s really badly spoken out in docs.
fn main(){ let x = 1; let y = 2; match x{ y => {println!("{}", y)}, _ => {} }}
The next beautiful iterator I love in Rust and use often, is peekable. What it does? It allow you to ‘peek’ (see) the next value in the iterator without consuming the next element from it.
peekable
Basically, it’s a normal iterator, and if you call .next(), .next(), .next() it…
.next()
I continue to crawl through leetcode problems, and I found that I use windows in about 30% of problems I solve. (do not confuse it with a name of a graphic shell to run Solitaire).
windows
It’s a part of brutal and almighty family of rust iterators, which may be scary, but as soon…
I got hooked on leetcode problems. No, I’m not trying to pass FAANG job interviews, my current job is more than satisfying by all means. Those tasks are really nice, and they are absolutely gorgeous way to learn Rust. They are like small Sudoku puzzles…
I’m glad I got to this problem well-augmented with good instruments (cargo asm and Criterion).
My problem was that a code I’ve expected to be fast, very fast, wasn’t. My random noise demo in SDL was able to crank up a nice 280 FPS at…
One part of ‘Rust liberation’ (compare to Python) was au revoir to GIL and single-threaded shame of the CPython. Your server has 48 cores, how you miserable are you to stick to a single one.
I’ve tried to work with SDL2 (sdl2 crate for Rust), and it’s SO AMAZING. It got everything I need and there is no…
I got a funky task: to prove that my benchmark doing the right thing. (turned out I used benchmark…