{"id":19389461,"url":"https://github.com/linksplatform/mem-rs","last_synced_at":"2026-04-13T04:25:31.790Z","repository":{"id":149666470,"uuid":"518405134","full_name":"linksplatform/mem-rs","owner":"linksplatform","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-10T22:44:47.000Z","size":231,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-11T00:23:09.283Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linksplatform.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-27T10:06:20.000Z","updated_at":"2026-04-10T22:24:59.000Z","dependencies_parsed_at":"2023-11-07T16:39:13.138Z","dependency_job_id":"e6d882b6-e7e9-462d-8ade-a27f55f22a49","html_url":"https://github.com/linksplatform/mem-rs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/linksplatform/mem-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linksplatform%2Fmem-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linksplatform%2Fmem-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linksplatform%2Fmem-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linksplatform%2Fmem-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linksplatform","download_url":"https://codeload.github.com/linksplatform/mem-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linksplatform%2Fmem-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31740032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T03:27:07.512Z","status":"ssl_error","status_checked_at":"2026-04-13T03:26:53.610Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T10:16:18.857Z","updated_at":"2026-04-13T04:25:31.780Z","avatar_url":"https://github.com/linksplatform.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# platform-mem\n\n[![Crates.io](https://img.shields.io/crates/v/platform-mem.svg)](https://crates.io/crates/platform-mem)\n[![License](https://img.shields.io/crates/l/platform-mem.svg)](LICENSE)\n\nA Rust library for low-level memory management with unified interface for allocator-backed and memory-mapped file storage.\n\n## Overview\n\n`platform-mem` provides the `RawMem` trait that abstracts over different memory backends:\n\n- **Allocator-based memory** (`Global`, `System`, `Alloc\u003cT, A\u003e`) - uses Rust's allocator API\n- **Memory-mapped files** (`FileMapped`, `TempFile`) - uses `mmap` for persistent or temporary file-backed storage\n\nThis allows writing generic code that works with any memory backend, making it easy to switch between heap allocation and file-mapped storage.\n\n## Features\n\n- **Unified `RawMem` trait** - common interface for growing, shrinking, and accessing memory\n- **Type-erased memory** via `ErasedMem` - enables dynamic dispatch with `Box\u003cdyn ErasedMem\u003cItem = T\u003e\u003e`\n- **Memory-mapped files** - persistent storage with automatic page management\n- **Temporary file storage** - anonymous file-backed memory that's cleaned up on drop\n- **Safe growth operations** - `grow_filled`, `grow_zeroed`, `grow_from_slice`, and more\n- **Thread-safe** - all memory types implement `Send + Sync`\n- **Async memory operations** (optional) - async mmap access with `AsyncFileMem` via dedicated I/O thread\n\n## Installation\n\nAdd to your `Cargo.toml`:\n\n```toml\n[dependencies]\nplatform-mem = \"0.1\"\n```\n\n**Note:** This crate uses Rust edition 2024 and works on stable Rust. It uses the [`allocator-api2`](https://crates.io/crates/allocator-api2) crate to provide allocator API functionality on stable Rust.\n\n### Optional Features\n\nTo enable async memory operations:\n\n```toml\n[dependencies]\nplatform-mem = { version = \"0.1\", features = [\"async\"] }\n```\n\n## Usage\n\n### Basic Example with Global Allocator\n\n```rust,ignore\nuse platform_mem::{Global, RawMem};\n\nfn main() -\u003e Result\u003c(), platform_mem::Error\u003e {\n    let mut mem = Global::\u003cu64\u003e::new();\n\n    // Grow memory and fill with value\n    mem.grow_filled(10, 42)?;\n    assert_eq!(mem.allocated(), \u0026[42u64; 10]);\n\n    // Grow more from a slice\n    mem.grow_from_slice(\u0026[1, 2, 3])?;\n    assert_eq!(mem.allocated().len(), 13);\n\n    // Shrink by 5 elements\n    mem.shrink(5)?;\n    assert_eq!(mem.allocated().len(), 8);\n\n    Ok(())\n}\n```\n\n### Memory-Mapped File Storage\n\n```rust,ignore\nuse platform_mem::{FileMapped, RawMem};\n\nfn main() -\u003e Result\u003c(), platform_mem::Error\u003e {\n    // Create memory mapped to a file\n    let mut mem = FileMapped::\u003cu64\u003e::from_path(\"data.bin\")?;\n\n    // Data persists across program runs\n    unsafe {\n        mem.grow_zeroed(1000)?;\n    }\n\n    // Modify the memory\n    mem.allocated_mut()[0] = 123;\n\n    Ok(())\n}\n```\n\n### Temporary File Storage\n\n```rust,ignore\nuse platform_mem::{TempFile, RawMem};\n\nfn main() -\u003e Result\u003c(), platform_mem::Error\u003e {\n    // Anonymous temporary file - cleaned up on drop\n    let mut mem = TempFile::\u003cu8\u003e::new()?;\n\n    mem.grow_from_slice(b\"hello world\")?;\n    assert_eq!(mem.allocated(), b\"hello world\");\n\n    Ok(())\n}\n```\n\n### Generic Code with `RawMem`\n\n```rust,ignore\nuse platform_mem::RawMem;\n\nfn process_data\u003cM: RawMem\u003cItem = u32\u003e\u003e(mem: \u0026mut M) -\u003e Result\u003c(), platform_mem::Error\u003e {\n    mem.grow_filled(100, 0)?;\n\n    for (i, slot) in mem.allocated_mut().iter_mut().enumerate() {\n        *slot = i as u32;\n    }\n\n    Ok(())\n}\n```\n\n### Type-Erased Memory with `ErasedMem`\n\n```rust,ignore\nuse platform_mem::{ErasedMem, Global, RawMem};\n\nfn main() {\n    // Use dynamic dispatch when the memory type isn't known at compile time\n    let mem: Box\u003cdyn ErasedMem\u003cItem = u64\u003e + Send + Sync\u003e =\n        Box::new(Global::\u003cu64\u003e::new());\n}\n```\n\n### Async File Memory (requires `async` feature)\n\n```rust,ignore\nuse platform_mem::AsyncFileMem;\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), platform_mem::Error\u003e {\n    // Create async mmap-backed memory with a dedicated I/O thread.\n    // Page faults are handled by the I/O thread, not the async runtime.\n    let mem = AsyncFileMem::\u003cu64\u003e::from_path(\"async_data.bin\")?;\n\n    // Async grow operations (dispatched to I/O thread)\n    mem.grow_filled(100, 42).await?;\n\n    // Read/write via I/O thread (non-blocking for async callers)\n    mem.set(0, 123).await?;\n    assert_eq!(mem.get(0).await?, Some(123));\n\n    // Data is synced to disk when AsyncFileMem is dropped\n    Ok(())\n}\n```\n\n## API Overview\n\n### `RawMem` Trait\n\nThe core trait providing memory operations:\n\n| Method | Description |\n|--------|-------------|\n| `allocated()` | Returns a slice of the initialized memory |\n| `allocated_mut()` | Returns a mutable slice of the initialized memory |\n| `grow(addition, fill)` | Grows memory by `addition` elements with custom initialization |\n| `shrink(cap)` | Shrinks memory by `cap` elements |\n| `grow_filled(cap, value)` | Grows and fills with cloned values |\n| `grow_zeroed(cap)` | Grows and zero-initializes (unsafe for non-zeroable types) |\n| `grow_from_slice(src)` | Grows and copies from a slice |\n| `grow_with(addition, f)` | Grows and initializes with a closure |\n| `grow_within(range)` | Grows by cloning a sub-range of existing data |\n| `grow_assumed(cap)` | Grows assuming data is already initialized (unsafe) |\n\n### Memory Types\n\n| Type | Description |\n|------|-------------|\n| `Global\u003cT\u003e` | Uses Rust's global allocator |\n| `System\u003cT\u003e` | Uses the system allocator |\n| `Alloc\u003cT, A\u003e` | Generic over any `Allocator` |\n| `FileMapped\u003cT\u003e` | Memory-mapped file storage |\n| `TempFile\u003cT\u003e` | Temporary file-backed memory |\n| `AsyncFileMem\u003cT\u003e` | Async mmap access via dedicated I/O thread (requires `async` feature) |\n\n## Error Handling\n\nThe crate defines an `Error` enum with these variants:\n\n- `CapacityOverflow` - Requested capacity exceeds `isize::MAX` bytes\n- `OverGrow` - Tried to grow more than available space\n- `AllocError` - Allocator failed to allocate/reallocate\n- `System` - I/O error from file operations\n\n## License\n\nThis project is released into the public domain under the [Unlicense](LICENSE).\n\n## Related Projects\n\n- [doublets-rs](https://github.com/linksplatform/doublets-rs) - Doublet links data structure using this memory library\n- [LinksPlatform](https://github.com/linksplatform) - The Links Platform organization\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinksplatform%2Fmem-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinksplatform%2Fmem-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinksplatform%2Fmem-rs/lists"}