first version for blog

This commit is contained in:
2022-06-16 16:45:30 +01:00
parent 9b41b7ce44
commit 7e9e16690e
14 changed files with 79 additions and 811 deletions

10
heap-program/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "heap-program"
version = "0.1.0"
edition = "2021"
[dependencies]
dhat = "0.3.0"
[features]
dhat-heap = [] # if you are doing heap profiling

35
heap-program/src/main.rs Normal file
View File

@ -0,0 +1,35 @@
use std::io::{self, Read};
fn stdin_boxed_str() -> Box<str> {
let mut buff = [0; 10];
let mut stdin = io::stdin(); // We get `Stdin` here.
stdin.read(&mut buff).unwrap();
let s = std::str::from_utf8(&buff).unwrap();
s.into()
}
fn stdin_string() -> String {
let mut buff = String::new();
std::io::stdin().read_line(&mut buff).unwrap();
buff
}
fn my_simple_program(a: i32) -> i32 {
let b = 10;
a + b
}
fn main() {
println!("{}", my_simple_program(5));
let boxed_str = stdin_boxed_str();
println!("boxed_str: {}", boxed_str);
let stdin_str = stdin_string();
println!("stdin_str: {}", stdin_str);
}