diff --git a/Cargo.lock b/Cargo.lock index 85b51d1..a3a1692 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,6 +204,10 @@ dependencies = [ "bitflags", ] +[[package]] +name = "refcell-program" +version = "0.1.0" + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -273,6 +277,10 @@ version = "0.1.0" name = "stack-program" version = "0.1.0" +[[package]] +name = "str-program" +version = "0.1.0" + [[package]] name = "string-dhat" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 33da0a4..3186475 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["stack-program", "stack-and-heap-program", "string-program", "box-str-program", "string-dhat", "box-str-dhat"] +members = ["stack-program", "stack-and-heap-program", "string-program", "box-str-program", "string-dhat", "box-str-dhat", "refcell-program", "str-program"] diff --git a/refcell-program/Cargo.toml b/refcell-program/Cargo.toml new file mode 100644 index 0000000..6ca9216 --- /dev/null +++ b/refcell-program/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "refcell-program" +version = "0.1.0" +edition = "2021" diff --git a/refcell-program/src/main.rs b/refcell-program/src/main.rs new file mode 100644 index 0000000..31cb573 --- /dev/null +++ b/refcell-program/src/main.rs @@ -0,0 +1,9 @@ +use std::cell::RefCell; + +fn main() { + let refcell_str: RefCell<&str> = RefCell::new("hello"); + + println!("refcell_str"); + let second = refcell_str.clone(); + println!("refcell_str second:"); +} diff --git a/str-program/Cargo.toml b/str-program/Cargo.toml new file mode 100644 index 0000000..28b42e9 --- /dev/null +++ b/str-program/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "str-program" +version = "0.1.0" +edition = "2021" diff --git a/str-program/src/main.rs b/str-program/src/main.rs new file mode 100644 index 0000000..ad9f57c --- /dev/null +++ b/str-program/src/main.rs @@ -0,0 +1,13 @@ +const NAME: &str = "asqar"; + +fn hello() -> u8 { + let hello = NAME; + println!("hello {}", hello); + 0 +} + +fn main() { + for _ in 1..5 { + let v = hello(); + } +} diff --git a/string-program/src/main.rs b/string-program/src/main.rs index f08a91d..903d4a0 100644 --- a/string-program/src/main.rs +++ b/string-program/src/main.rs @@ -1,5 +1,5 @@ fn main() { - let s = String::from("hello!"); + let s = String::from("hello"); println!("{}", s); println!("size of string on stack: {}", std::mem::size_of_val(&s)); }