This concept has somehow got me intrigued on a few occasions and I am sure majority of the readers find this interesting too.

Let’s start with what is a “variance”? In simple terms, it is about allowing a type to be interpreted as another type, provided there is some (subtyping) relation between the two.

If type T is a subtype of type U , then T can be provided wherever U is expected.

T some_t = create_T();
U some_u = t;

which is:

Cat some_cat = create_cat("fluffy");
Mammal some_mammal = cat;
Animal some_animal = mammal;
// or
Animal some_animal =…

Photo by Beth Macdonald on Unsplash

Rust has a very powerful pattern matching system. You can match literals, structs, enums, slices (of varying lengths), specific fields in a struct (via de-constructing), nested fields, references, ranges, etc.

Assuming we have a fair understanding of pattern matching in Rust, let’s explore the ref keyword and the relationship between ref and & , when it comes to pattern matching.


let x:i32 = 1;
match x {
ref y => println!("{}", *y),
_ => ()

The above snippet is a very simple example (It’s obvious that the “default” condition will never get hit. But here we can ignore…

In the world of high level languages like Java, Python, JavaScript, Ruby, Go, the developer mindset is not really tuned to understand one important thing — which is Memory. The reason being — the Garbage Collector as it keeps track of all the objects in the memory for you. But this comes at cost of the GC running alongside your program. On the other end of the spectrum where you have C, C++ you can extract maximum performance out of your system, but then this comes at the cost of you having to manage the memory yourself. …

Let’s have a look at the following code:

trait Animal {
fn talk(&self);
struct Cat {}
struct Dog {}
impl Animal for Cat {
fn talk(&self) {
impl Animal for Dog {
fn talk(&self) {
fn animal_talk(a: &dyn Animal) {;
fn main() {
let d = Dog {};
let c = Cat {};

We see that animal_talk()is invoked for both Catand Dog. But the function is not aware of the exact types. dyn tells the compiler to not determine the exact type and just be content with a…

When it comes to Kubernetes networking, Calico is widely used. One of the main reasons being its ease of use and the way it shapes up the network fabric. Calico is a pure L3 solution, where packets are routed in just the same manner as your regular Internet. Each node (eg. VM) acts like a vRouter, which means tools like traceroute, ping, tcpdump, etc just work as expected! Whether the packet is flowing from one container to another or container to another node (or vice-versa), its just treated as a flat network route (L3 hops). By default, there is no…

Before moving to understanding the mutable reference, let’s have a look at a very basic example in C.

int main() {
int i = 1;
i = 2;

This code compiles just fine. Let’s see its Rust equivalent.

fn main() {
let i:i32 = 1;
i = 2;

This fails with error:

error[E0384]: cannot assign twice to immutable variable `i`
--> src/
2 | let i = 20;
| - first assignment to `i`
3 | i = 2;
| ^^^^^ cannot assign twice to immutable variable

Rust treats its variables as immutable, unless specified like this:

CNI is being mentioned a lot in conjunction with Kubernetes. It is now become an integral part of Kubernetes, silently doing it’s job of connecting the pods across different nodes and being well adaptive in integrating different kind of network solutions (overlays, pure L3, etc). Having said that, it is not only present in Kubernetes. It in itself is a separate framework with it’s own specification and can be used not only with Kubernetes but also with other container orchestrators like Mesos, Openshift, etc.

So what is CNI? To put it succinctly, it is an interface between a network namespace…

Having a dynamic public IP can be really annoying when it comes to accessing the services in AWS, guarded by security groups (assuming you are a small shop and don’t have the VPN or AWS DirectConnect infra setup yet or maybe it is your personal AWS account.)

Anyway, it’s a bit tiring to open the browser, load AWS console , click on the security groups, edit it and then save it back. All this, so that you can ssh into your EC2 instance, for example. The worst is when AWS console has signed you out (due to inactivity) and then…

Here, we will cover a very simple and basic topic in Rust. The relation between reference (&) and Copy trait.

What happens above is that struct Cat is passed to thetest function. This compiles fine. Now let’s what happens if I add one more call to the functiontest:

error[E0382]: use of moved value: `c`
--> src/
10 | test (c);
| - value moved here
11 | test (c);
| ^ value used here after move
= note: move occurs because `c` has type `Cat`, which does not implement the `Copy` trait

The error is pretty simple…

vikram fugro

Open Source Software Enthusiast, Polyglot & Systems Generalist.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store