Skip to content

Universal MmapFile that can read any T - #8493

Merged
ffuugoo merged 14 commits into
devfrom
universal-mmap
Mar 25, 2026
Merged

ffuugoo merged 14 commits into
devfrom
universal-mmap

Conversation

@ffuugoo

@ffuugoo ffuugoo commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Implement MmapFile that does not depend on generic parameter T and implement UniversalRead/UniversalWrite for "any" T (e.g., single MmapFile can read u8/f32/u64/etc).

I've provided MmapUniversal<T> re-implementation based on MmapFile, thought I plan to completely replace it with MmapFile (either in this, or in a follow-up PR).

I've also added:

  • writeable flag to OpenOptions for runtime read/write control (e.g., similar to fs::OpenOptions::write)
  • and generic ReadOnly wrapper, that enforces I/O being read-only
    • runtime assert that writeable == false
    • and statically/at compile-time it only implements UniversalRead, but not UniversalWrite

My reasoning for this is:

  • it's just easier to implement, less helper-traits/generics
  • if we can specify read-only type in code (e.g., use MmapUniversalRo), we can as well specify writeable: false
    • it's potentially more error-prone, yes...
    • but we can enforce it with ReadOnly wrapper
  • ReadOnly wrapper is an additional generic
    • but it's absolutely trivial
    • and generic for all current and future UniversalRead implementations

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@ffuugoo
ffuugoo force-pushed the universal-mmap branch 2 times, most recently from 0ddda5a to 4ee42ef Compare March 24, 2026 18:37
@ffuugoo
ffuugoo marked this pull request as ready for review March 25, 2026 11:18
@ffuugoo
ffuugoo requested review from coszio, generall and xzfc March 25, 2026 11:18
@coderabbitai

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@xzfc xzfc mentioned this pull request Mar 25, 2026
3 of 9 tasks
@@ -1,5 +1,7 @@
use std::path::{Path, PathBuf};

use super::*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

glob imports are considered antipattern

@generall generall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks ok, but I would want @xzfc to take a look at ForceAnyBitPattern and related changes, as I don't understand any of those

coderabbitai[bot]

This comment was marked as duplicate.

@ffuugoo
ffuugoo merged commit a7550f8 into dev Mar 25, 2026
15 checks passed
@ffuugoo
ffuugoo deleted the universal-mmap branch March 25, 2026 15:57
@ffuugoo ffuugoo mentioned this pull request Mar 25, 2026
7 of 9 tasks
@xzfc xzfc mentioned this pull request Mar 26, 2026
@generall generall added this to the Universal IO milestone Mar 26, 2026
generall pushed a commit that referenced this pull request Mar 26, 2026
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
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