Move.

Post

Share your knowledge.

skywinder.
Jan 23, 2025
Expert Q&A

How to resolve mutable borrow error in Rust function?

I'm encountering an error while trying to get a value from an object in two places within the same Rust function. The error states it's still being mutably borrowed. How do I resolve this?

  • Move CLI
3
2
Share
Comments
.

Answers

2
Xavier.eth.
Jan 23 2025, 15:56

To resolve this, ensure that the first mutable reference (b1_obj) goes out of scope before attempting to borrow the object again with the second mutable reference (b2_obj).

3
Best Answer
Comments
.
Grizzly.
Jan 23 2025, 09:10

This error occurs because you cannot have more than one mutable reference to the same object at the same time in Rust.

1
Comments
.

Do you know the answer?

Please log in and share it.

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148Posts231Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
We use cookies to ensure you get the best experience on our website.
More info