rust-learn

rust-learn

some tips

  1. #![allow(dead_code)] allow unused variable
  2. #[allow(non_camel_case_types)] Use an attribute to silence warning.
  3. #[derive(Debug)] an attribute that provides a basic implementation of the Debug trait for the following struct.
  4. cargo +nightly rustc -- -Zunstable-options --pretty=expanded See what the compiler did
  5. fmt::Display:
impl fmt::Display for Structure {
    // This trait requires `fmt` with this exact signature.
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        // Write strictly the first element into the supplied output
        // stream: `f`. Returns `fmt::Result` which indicates whether the
        // operation succeeded or failed. Note that `write!` uses syntax which
        // is very similar to `println!`.
        write!(f, "{}", self.0)
    }
}
  1. #[derive( PartialEq)] add it so that assert_eq!() can be used.
  2. #![allow(unreachable_code)]

puzzle

  1. Custom Types/Structures/let bottom_right = Point { x: 5.2, ..point };

cargo

  1. 使用本地crate

Cargo.toml[dependencies]后加入crate_name = {path = "crate_path"}

猜你喜欢

转载自www.cnblogs.com/wheszza/p/12577983.html