从零开始重新认识rust

// 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
}

数组和引用内存概览

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值