// compile rustc main -o out/main
fn main(){
// / hey here I am going to talk about rust
// / TYPE SYSTEM
// / 1. number type for interger like 1, 2, -1
// / 2. for machain like type
// / 3. float type
// / 4. bool type
// / 5. char type like a 'a' '\n'
// / 6. tuple type like mix other type in ('i',"fuck",-1)
// / 7. () type, has a value ()
// / 8. general(c like) struct type like S{x:12,y:190.0}
// / 9. tuple struct type like S(120,'x')
// / 10. None struct type like like struct E
// / 11. enum type like Attend::Late(5)
// / 12. Box generic type like Box::new(Late(5))
// / 13. ref type like &s.y, &mut y;
// / 14. String type like "some".to_string()
// / 15. &str type like "hello", &s[0..12]
// / 16. fuck how to say this type, but you can view it as like c array type like [1.0,2.0]
// / 17. vector type is a dynamic type on len like vec![0.11,0.22]
// / 18. ref to c like array type like: &v[10..20], &mut a[..]
// / 19. trait instance type like value as &Any, &mut file as mut Read
// / 20. function type like i32::add;
// / 21. closure type like |a,b| a*a + b * b
// / now I order you to view any value is a type and the above right handside is not define the type, they are value
// / make a demo by your own and make sure you understand the fucking TYPE SYSTEM!!! AND I WON'T COMMEND ANYMORE!!!
let _big_val = std::i32::MAX;
let _x = _big_val.wrapping_add(1);// it is safe operation, this is like MAX + 1, it will overflow in c++
assert_eq!(10_i8 as u16, 10_u16);// true
assert_eq!(false as i32, 0);// true
println!("{}",'a');
// now view ref, Box and unsafe pointer are belong to pointer type
// raw pointer are: *mut <T> *const <T>, use in unsafe block
// now view c like array, vector, slice as a series value in memory
// noticed vector value is storage in heap
// iter and into_iter, not now
// well done
}
从零开始重新认识rust
最新推荐文章于 2024-10-02 13:27:19 发布