lifetimes and returning borrowed values. Also print pointer address
This commit is contained in:
parent
c5ebaa16dd
commit
d2bc5d2981
29
src/main.rs
29
src/main.rs
|
@ -1,13 +1,22 @@
|
|||
fn main() {
|
||||
let mut a: i32 = 10;
|
||||
let mut b: &mut i32 = &mut a;
|
||||
#[derive(Debug)]
|
||||
struct Point(i32, i32);
|
||||
|
||||
{
|
||||
let c: &mut i32 = &mut b;
|
||||
*c = 20;
|
||||
println!("c: {c}");
|
||||
fn left_most<'a>(p1: &'a Point, p2: &'a Point) -> &'a Point {
|
||||
if p1.0 < p2.0 {
|
||||
p1
|
||||
} else {
|
||||
p2
|
||||
}
|
||||
|
||||
println!("a: {a}");
|
||||
//println!("b: {b}");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p1: Point = Point(10, 10);
|
||||
let p2: Point = Point(20, 20);
|
||||
{
|
||||
let p3: &Point = left_most(&p1, &p2);
|
||||
|
||||
println!("left_most: {:?}", p3);
|
||||
println!("p3: {:p}", &p3);
|
||||
}
|
||||
println!("p1: {:p}", &p1);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rustc_fingerprint":16320356917333427825,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.1 (90743e729 2023-01-10)\nbinary: rustc\ncommit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6\ncommit-date: 2023-01-10\nhost: x86_64-unknown-linux-gnu\nrelease: 1.66.1\nLLVM version: 15.0.2\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
|
||||
{"rustc_fingerprint":16320356917333427825,"outputs":{"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.1 (90743e729 2023-01-10)\nbinary: rustc\ncommit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6\ncommit-date: 2023-01-10\nhost: x86_64-unknown-linux-gnu\nrelease: 1.66.1\nLLVM version: 15.0.2\n","stderr":""}},"successes":{}}
|
|
@ -1 +0,0 @@
|
|||
{"rustc":7419878829587384386,"features":"[]","target":14602933489408981941,"profile":7309141686862299243,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/basics00-2aafd7e9003de7a7/dep-bin-basics00"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
This file has an mtime of when this was started.
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
This file has an mtime of when this was started.
|
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"rustc":7419878829587384386,"features":"[]","target":14602933489408981941,"profile":1021633075455700787,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/basics00-3922c6fa78ff0509/dep-test-bin-basics00"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
|
@ -1,5 +0,0 @@
|
|||
/home/vbatts/tmp.rust/basics00/target/debug/deps/basics00-2aafd7e9003de7a7.rmeta: src/main.rs
|
||||
|
||||
/home/vbatts/tmp.rust/basics00/target/debug/deps/basics00-2aafd7e9003de7a7.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
|
@ -1,5 +0,0 @@
|
|||
/home/vbatts/tmp.rust/basics00/target/debug/deps/basics00-3922c6fa78ff0509.rmeta: src/main.rs
|
||||
|
||||
/home/vbatts/tmp.rust/basics00/target/debug/deps/basics00-3922c6fa78ff0509.d: src/main.rs
|
||||
|
||||
src/main.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue