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

Explore interior mutability #79

Open
jonathanpallant opened this issue Apr 21, 2023 · 2 comments
Open

Explore interior mutability #79

jonathanpallant opened this issue Apr 21, 2023 · 2 comments

Comments

@jonathanpallant
Copy link
Collaborator

Now that critical-section is a thing, maybe we can consider interior mutability:

  • Volume can hold an &VolumeManager
  • Directory and File can hold an &Volume
let volume = volume_mgr.get_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
let file = root_dir.open("HELLO.TXT")?;
let mut buffer = [0u8; 64];
let contents = file.read_to_buffer(&mut buffer)?;
@thejpster
Copy link
Member

So one issue here is stopping people opening the same volume twice, but allowing all the objects to be stashed in a struct for later use (so they can't refer to each other).

Perhaps the VolumeManager can hold all the volumes internally and lend out &mut Volume references cheaply, but only for one Volume at a time. You could even const generic the number of Volumes a VolumeManager can hold (one is usually fine, but sometimes there's an EFI partition first or something). Then I think for opening files you can either get a File (which holds a &Volume) or a RawFile (which does not, but does hold some unique ID for the Volume so it'll panic if you use it with the wrong Volume in future).

@thejpster
Copy link
Member

Looked at this in #103 is a start on this, but using &mut to start.

Also there's an old branch: https://github.com/rust-embedded-community/embedded-sdmmc-rs/tree/make_api_immutable

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

No branches or pull requests

2 participants