Rust for C++ developers part 4: Enums, destructuring and pattern matching

Rust enums are similar to the ones in C++ with one subtle difference - Rust ones allow you to bundle additional data with each variant. This feature combined with destructuring and pattern matching is very powerful. What I find interesting is that each feature is nothing special on its own but combining them together allows you to write very elegant code. In my opinion these are one of the coolest features of Rust. Let's start with enums.

Read more…

Rust for C++ developers part 3: Ownership and Borrowing

This is the third post from my Rust for C++ developers series. With references and traits covered now is a good time to learn about ownership and borrowing. Rust is a system programming language and as such the memory management is a very important topic. I assume you are already familiar with what stack and heap is and how it works in general. If not - you can read this section from the Rust book. If you are not familiar with the references in Rust and you have missed part 2 I strongly recommend to read it now. You need to understand how references work in Rust to grasp this post. But before talking about borrowing let's discuss memory ownership.

Read more…

Rust for C++ developers part 2: References, Structs and Traits

This is the second post from my Rust for C++ developers post series and it will focus on structs, traits and some basic data structures embedded into the language. Similar to part 1 this post will continue exploring Rust's syntax and making parallels with C++. For each topic I'll provide links to the Rust book. You don't need a development environment for this post too. Rust Playground should be enough to run the examples and experiment with them. Let's get started.

Read more…

Rust for C++ developers part 1: Basic syntax

This is the first post from my Rust for C++ developers post series and it will focus mainly on the basic syntax. This includes variables, functions, conditional operators and some common Rust patterns around them. I'll try to walk you through some syntactic and conceptual similarities and differences between the two languages based on my experience. To follow this post you don't need to setup a compiler or an editor. You can write code online at the Rust Playground and it should be enough to run the examples. For each topic discussed in the post I'll provide links to the Rust book where you can find more detailed information. Feel free to skip them if you are in a hurry but if you have got the time it's worth to at least skim through the sections.

Read more…

Rust for C++ devs

If you want to learn Rust there are a lot of great and free resources online for you. My favourite one is The Rust Programming Language book also known as "The Rust Book". It's considered the official Rust tutorial and it's one of my favourite Rust books. Before picking up Rust I had around 10 years of C++ experience. While reading the book I noticed there are a lot of conceptual similarities between the two languages and I was thinking how nice it would be to have Rust explained by using the knowledge I already had from C++. It would have helped me to build an intuition for the language and how to write more idiomatic Rust code. The Rust book is definitely good but it doesn't make any assumptions about your background. If you already know what RAII is, how computer memory is organised, what a pointer/reference is you will find some of the material there redundant. When you read about something you already know you ask yourself "Is this the same as in C++ or there is a catch?" In this post I'll try to help you build intuition about how Rust works and how idiomatic Rust code looks like by sharing code samples, providing brief explanations and pointing you to the corresponding chapters from the Rust book to get the full picture. Where possible I'll make parallels with C++ and point out the differences and similarities between the two. I hope it will make your learning process a bit faster and a bit more comfortable.

Read more…

Rust Proc Macros: A Beginner's Journey

Who am I and what is this post about

Recently I started working professionally with Rust and it wasn't long before I stumbled upon proc macros. I had to make some changes to a relatively complex (for me) macro which generates traits and implementations for them. Reading about macros (and especially proc macros) in Rust created some associations with C++ metaprogramming which is not exactly my cup of tea. As a result I was determined not to enjoy the task. However it turned out that proc macros aren't that bad. They are very different from the regular Rust one sees every day but they are not black magic. And you can do useful stuff with them.

So why this post? There are a lot of resources for learning proc macros out there. I've read some of them but despite that there were things which just didn't click for me in the beginning. I needed something more to reach the 'now this makes sense' moment. So after gaining some knowledge I decided to write this post and share my experience. And more specifically - the things I didn't initially understand.

Should you read it? The short answer is NO :). If you aren't a complete proc macro newbie - there is nothing for you here. I'll be very grateful if you want to read it and share your feedback/advise. But don't be disappointed if you expect to learn something new and you only see obvious stuff. If you are just starting to learn proc macros this post might help. But people are different - hard things for me are maybe easy for you and the other way around.

Read more…

Brief Introduction to Crypto++

At some point in your life as a software engineer you will have to write code involving cryptography (crypto for short). You might need to implement a password authentication system by keeping salted password hashes for your users or add encryption for your custom binary protocol implementation or save some files securely on disk, etc. This is usually harder than it sounds and you will have to use some crypto library to get the job done.

In this post I want to write a really quick and short introduction to Crypto++, a C++ cryptographic library. My first experience with it led a lot of questions. Reading the documentation and googling answers took me some time so I want to share my experience. Hopefully you will find the information in this post helpful and will save you some time.

Read more…

The book is published!

Finally "SCTP in Theory and Practice" is ready. This is a really exciting moment for me. The book is available on Leanpub, but as I reader of my blog you can get 20% discount till the end of May 2020 by using this coupon.

/post-files/the-book-is-published/cover.jpg

What to expect compared to the blog posts: - Huge part of the text is rewritten to be easier to read, shorter (where possible) and with consistent style. - All the diagrams are changed with better looking ones. - Topics are rearranged in more logical order. - All the sample code from hands on chapters of the book is rewritten. This is the biggest change in the book. The essential client-server code is separated and as a result the code samples are shorter and easier to follow. - You can read the material offline in epub, mobi or PDF.

SCTP in Theory and Practice - my new e-book

I am glad to share that the e-book I wrote about in my last post is almost finished. I expected to finish it a lot faster as I already had the blog posts, but writing is not an easy job, especially when you do it for the first time. But luckily my book is almost ready and I will launch it on Leanpub by the end of the month.

EDIT (28.04.2020): The book is already published on Leanpub.

SCTP in Theory and Practice

This is the title of the book. It is around 120 pages long and contains 11 chapters which more or less follow the posts in this blog. You can see the page of the book on LeanPub here. You probably wonder what is changed? In nutshell:

  • Huge part of the text is rewritten to be easier to read, shorter (where possible) and with consistent style.

  • All the diagrams are changed with better looking ones.

  • Topics are rearranged in more logical order.

  • All the sample code from hands on chapters of the book is rewritten. Actually this is the biggest change in the book. The old code contained a lot of chunks which were needed but not related to SCTP. The new version has these parts reworked and separated from the essential SCTP client/server code. As a result the code samples are shorter and I hope easier to follow and understand.

  • And of course thanks to being an e-book you can read the material offline in epub, mobi or PDF.

  • In the previous post I promised to include unpublished bonus material in the book. Unfortunately the additional material I want to write about is still not good enough so I won't include it in the book.

At this point I don't plan paper version of the book. This is my first writing so probably I made some mistakes that I want to fix fast easy and free. Keeping the book in e-version only makes it easier to make fixes and add chapters on the go. And thanks to Leanpub you have to purchase the book only once and you will receive all updates for free afterwards.

Getting the book

You can purchase the book on Leanpub here.