Lending immutably

When lending, the default is to lend the data immutably, meaning that the borrowed data can be read, but not changed. We can lend immutably to more than one borrower at the same time, which is safe because none of them can change the borrowed data, and so they can't interfere with each other by changing the data value unexpectedly.

To create an immutable borrow, we prefix the expression producing the data value with &, like this:

borrow_ownership(&main_3);

Here, we're calling a function called borrow_ownership, and passing it a data value borrowed from the main_3 variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.254.151