Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap environments in RefCell #441

Closed
wants to merge 2 commits into from
Closed

Wrap environments in RefCell #441

wants to merge 2 commits into from

Conversation

kinrezC
Copy link
Contributor

@kinrezC kinrezC commented Aug 17, 2023

Currently in order to add environments to the manager one must carry a mutable reference to the manager. Using RefCell allows you to track an immutable reference to the manager while allowing for interior mutability on the environments.

@Autoparallel
Copy link
Collaborator

Does it matter if we carry around a mutable reference to manager?

@Autoparallel
Copy link
Collaborator

If we do want to remove &mut self on the methods, can we maybe make a method for the manager that is something like:

pub fn get_environment<S: Into<String>>(&self, label: S) -> Option<&Environment> {
    self.environments.borrow().get(label)
}

@kinrezC
Copy link
Contributor Author

kinrezC commented Aug 17, 2023

Does it matter if we carry around a mutable reference to manager?

I figure there may be cases where you want to carry many references to the manager at one time (e.g. you want to create several environments with different configurations?). It wouldn't be possible to satisfy rust borrow rules in this scenario.

@0xJepsen
Copy link
Collaborator

Does it matter if we carry around a mutable reference to manager?

I figure there may be cases where you want to carry many references to the manager at one time (e.g. you want to create several environments with different configurations?). It wouldn't be possible to satisfy rust borrow rules in this scenario.

I think this is a good change and am for merging this

@0xJepsen 0xJepsen self-requested a review August 17, 2023 20:23
Copy link
Collaborator

@0xJepsen 0xJepsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Autoparallel
Copy link
Collaborator

Autoparallel commented Aug 17, 2023

I figure there may be cases where you want to carry many references to the manager at one time (e.g. you want to create several environments with different configurations?). It wouldn't be possible to satisfy rust borrow rules in this scenario.

I don't think I follow. With the current set up, I can create multiple environments with different configs and I don't run into any borrow rules.

I can just

let mut manager = Manager::new();
manager.add_environment("label",..);
manager.add_environment("label_2",..);
// ~ etc.

It would only matter if we have a function like so:

fn do_something(mut manager: Manager) ..

@0xJepsen
Copy link
Collaborator

Maybe we close this for now? Thoughts @kinrezC and @Autoparallel?

@Autoparallel
Copy link
Collaborator

Maybe we close this for now? Thoughts @kinrezC and @Autoparallel?

That's my preference. I think we should revisit something like this if we run into an issue down the road in making simulations.

@0xJepsen 0xJepsen closed this Aug 17, 2023
@0xJepsen 0xJepsen deleted the fix/manager-mutability branch October 10, 2023 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants