rust-learn
some tips
#![allow(dead_code)]
allow unused variable#[allow(non_camel_case_types)]
Use an attribute to silence warning.#[derive(Debug)]
an attribute that provides a basic implementation of the Debug trait for the following struct.cargo +nightly rustc -- -Zunstable-options --pretty=expanded
See what the compiler didfmt::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)
}
}
#[derive( PartialEq)]
add it so thatassert_eq!()
can be used.#![allow(unreachable_code)]
puzzle
- Custom Types/Structures/let bottom_right = Point { x: 5.2, ..point };
cargo
- 使用本地crate
在
Cargo.toml
的[dependencies]
后加入crate_name = {path = "crate_path"}