Rust lang: Why is the temporary/local variable created behind a reference not dropped after the scope ends?

Can someone help me explaining the following code? In scope 1 and 2, the local variable created get dropped when their scope ends which is as expected. However in scope 3 and 4, it seems that the local variable declared behind a reference did not get dropped, the local variable declared in scope 4 is… Read More Rust lang: Why is the temporary/local variable created behind a reference not dropped after the scope ends?

why can't I write element to a moved position in array in Rust, but I can do it in tuple

I destruct an element from a tuple, and then write back a new element. It works. let mut a = ("111".to_string(), "222".to_string()); let (b,_) = a; a.0 = "333".to_string(); println!("{:?}", a); //output:("333", "222") But I can’t do it in an array: let mut a = ["111".to_string(), "222".to_string()]; let [b,_] = a; a[0] = "333".to_string(); ^^^^… Read More why can't I write element to a moved position in array in Rust, but I can do it in tuple

Why is struct consumed when using self but not when deconsturcting?

I started learning rust from https://doc.rust-lang.org/rust-by-example/, and as far as I understand rust uses move on an assignment, and you explicitly have to tell it to copy with clone(). #[derive(Debug)] struct Point { x: f32, y: f32, } impl Point { fn destroy(self) { let Point{x, y} = self; println!("pt is consumed: {}, {}", x,… Read More Why is struct consumed when using self but not when deconsturcting?

Do I need to specify 'drop(item)' if i write a custom drop implementation for a struct? Rust

I’m working with OpenGL in rust currently. and i want to create objects like VAOs and Textures into structs now, i wrote a custom drop implementation that calls something like glDeleteTexture when the objects lifetime is finished so that it clears up the memory in VRAM. Will the actual data of the object still remain… Read More Do I need to specify 'drop(item)' if i write a custom drop implementation for a struct? Rust

how to execute a function in a file in pymodule

This is an official py03 example. Python::with_gil(|py| -> PyResult<Py<PyAny>> { let py_app = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/app.py")); let app: Py<PyAny> = PyModule::from_code(py, py_app, "", "")? .getattr("test_function")? .into(); app.call0(py) }) my local app.py contains the following where the import is the rust module: import GQLwrapper print("running app.py") def test_function: print("running test function") The rust call is running the… Read More how to execute a function in a file in pymodule