Quick Start into Rust for developers

Published by admin. 13. November 2021 2 Comments

In this post, I will give a very brief overview into Rust for developers who are already familiar with other languages such as Python, Java, C, etc…

Traits

A trait is the equivalent to an interface in Java.

struct Rectangle {height: i32, width: i32}
// Test
/// Block
/// okay
trait Shape{
   fn surface(&self) ->  i32;
   fn circumference(&self) -> i32;
}

impl Rectangle {
   fn setSize(height: i32, width: i32) {
      self.height = height;
      self.width = width;
   }
}

impl Shape for Rectangle {
   fn surface(&self) -> i32 {
      self.height*self.width
   }
   fn curcumference(&self) -> i32 {
      (self.height+self.width)*2
   }
}

2 Comments

Kaikai says:

Hi 大胡子🧔 congratulations!you will be good at sharing something with nice people new life start!😄🧚‍♀️

admin says:

谢谢我最爱的开开😊

Leave a Reply

Your email address will not be published. Required fields are marked *