What is Borrow Checker?

Asked

Viewed 191 times

9

I was reading a little bit about Rust and I came across that term, I’d like to know:

  • What is Borrow Checker?
  • Is there any connection with Counting?
  • What would be the translation for this term in English?

1 answer

7


What is Borrow Checker?

It is the code parser contained in the compiler (it would not need to be but in Rust it is, part of the philosophy of language) that identifies whether the lifetime of objects is being respected.

When you have a reference to an object that reference has the property of it, then another reference can only have the object on loan, it does not become owner of the object and can not do what you want with it, for example can not destroy it.

In some cases the Rust parser can identify if everything is ok and places life-time annotations of the object for you, in other cases you, the programmer, should explicitly note to indicate that there is respect for the loan, which will prevent certain code constructs that would subvert you.

So it’s a static analysis (compile time) of the lifetime of the object allowing only its owner to destroy it. It gives Rust reference security without creating cost to executable.

Is there any relationship with Resemblance Counting?

No direct. In a way it has if we consider that it is almost an opposition to it. While the loan ensures that only one reference has the property of the object and it is borrowed through other references, the reference count allows several references to own the object together, not needing to make a loan. It is a runtime mechanism that needs to store and control a reference counter and indicate if the object can be destroyed, so it costs.

What would be the translation for this term in English?

Loan analyzer? Property analyzer could fit too, but obviously not the most correct.

  • I’ll use the term in English anyway, in Portuguese it doesn’t sound very natural

  • "Loan Verifier", literal same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.