M
M
MDtox2018-10-11 01:53:18
Rust
MDtox, 2018-10-11 01:53:18

I do not understand when you need a loan?

It's hard for me to understand when to use links, and when the arguments themselves? Like self and &self or when should the function return a reference(fn some_fn(v) -> (&)i32)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Potanin, 2018-10-18
@potan

If a function receives a reference, then it does not control its lifetime. When a function has received an object not by reference, it owns it and no one else has access to it until the function returns it or passes it somewhere. If the function did not return it and did not save it anywhere, the memory occupied by the object is freed when the function ends.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question