learn_rust_demo 0.1.0

learn rust publish demo
Documentation
// fn main() {
//     let s = String::from("Hello world");
//     let tmp = first_word(&s);
//     println!("{}", tmp)
// }

// fn first_word(s: &str) -> &str {
//     let bytes = s.as_bytes();
//     for (i, &item) in bytes.iter().enumerate() {
//         if item == b' ' {
//             return &s[..i];
//         }
//     }
//     &s[..]
// }

// mod rectangle;

// use std::collections::HashMap;

// fn main() {
//     // let s1 = String::from("Hello");
//     // let s2 = String::from("World");

//     // let s3 = s1 + &s2;
//     // println!("{}", s3);
//     // // println!("{}", s1);
//     // println!("{}", s2);

//     let mut scores = HashMap::new();

//     scores.insert("blue", 123);
//     scores.insert("red", 10);

//     scores.entry("yellow").or_insert(20);
//     println!("{:?}", scores);
//     panic!(":(")
// }

// struct Point<T, U> {
//     x: T,
//     y: U,
// }

// impl<T, U> Point<T, U> {
//     fn mixup<V, W>(self, other: Point<V, W>) -> Point<T, W> {
//         Point {
//             x: self.x,
//             y: other.y,
//         }
//     }
// }

// fn main() {
//     let p1 = Point { x: 1, y: 2 };
//     let p2 = Point { x: 'a', y: 'b' };
//     let p3 = p1.mixup(p2);
//     println!("x:{}, y:{}", p3.x, p3.y);
//     println!("x:{}, y:{}", p1.x, p1.y);
//     // println!("x:{}, y:{}", p2.x, p2.y);
// }

// use learn_rust::NewsArticle;
// // use learn_rust::Tweet;
// use learn_rust::Summary;

// pub fn notify(item: &impl Summary) {
//     println!("{}", item.summarize());
// }

// fn main() {
//     let tmp = NewsArticle {
//         author: String::from("zj"),
//         content: String::from("zj-content"),
//         headline: String::from("zj-headline"),
//         location: String::from("shenzhen"),
//     };

//     notify(&tmp)
// }

fn main() {
    // let s1 = "abc";
    // let s2 = "defg";

    // fn compare<'a>(t1: &'a str, t2: &'a str) -> &'a str {
    //     if t1.len() > t2.len() {
    //         t1
    //     } else {
    //         t2
    //     }
    // }

    // let x = compare(s1, s2);
    // println!("{}", x);
    let v1 = vec![1, 2, 3];
    let v2: Vec<_> = v1.iter().map(|x| x + 1).collect();
    assert_eq!(v2, vec![2, 3, 4]);
}