How do I print the type of a variable?
I have the following: let mut my_number = 32.90; How do I print the type of my_number? Using type and type_of did not work. Is there another way I can print the number’s type? 13 Answers 13
I have the following: let mut my_number = 32.90; How do I print the type of my_number? Using type and type_of did not work. Is there another way I can print the number’s type? 13 Answers 13
As far as I know, reference/pointer aliasing can hinder the compiler’s ability to generate optimized code, since they must ensure the generated binary behaves correctly in the case where the two references/pointers indeed alias. For instance, in the following C code, void adds(int *a, int *b) { *a += *b; *a += *b; } when … Read more
struct SemanticDirection; fn main() {} warning: struct is never used: `SemanticDirection` –> src/main.rs:1:1 | 1 | struct SemanticDirection; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default I will turn these warnings back on for anything serious, but I am just tinkering with the language and this is driving me bats. I tried adding #[allow(dead_code)] … Read more
How do I concatenate the following combinations of types: str and str String and str String and String 8 Answers 8
I’ve implemented the following method and unit test: use std::fs::File; use std::path::Path; use std::io::prelude::*; fn read_file(path: &Path) { let mut file = File::open(path).unwrap(); let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); println!(“{}”, contents); } #[test] fn test_read_file() { let path = &Path::new(“/etc/hosts”); println!(“{:?}”, path); read_file(path); } I run the unit test this way: rustc –test app.rs; … Read more
Why does Rust have String and str? What are the differences between String and str? When does one use String instead of str and vice versa? Is one of them getting deprecated? 1Best Answer 11 String is the dynamic heap string type, like Vec: use it when you need to own or modify your string … Read more