Ben Chuanlong Du's Blog

It is never too late to learn.

Constraints on Types in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Ways to Make Sure that a Type in Rust Satisfy Certain Conditions

  1. type bounds using the where clause

  2. disable users from constructing instances of a struct and provide initialized instances (with …

Memory Layout in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Different Types of Memory in Rust

Rust has 3 different types of memory: static memory, stack memory and heap memory.

  1. Static variables live in static memory and is determined at compile time. It is suggested that you define large data variables as static so that they live in the static memory instead of stack memory to avoid stack overflow problems. Of course, another way is to put those variables into heap memory (but at the cost of slight performance loss).

Cast Types of Columns in Pandas

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. You can use the method Series.astype to cast the type of a series.

  2. Series.astype(str) converts NaNs to the string literal nan. This is often NOT what people want. A better way is to use Series.astype(object)

Sum Type in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Enum is the preferred way to constrcut a sum type of several types (which does not implemente the same trait).

The Rust crate either provides an enum Either (with variants Left …