Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/optozorax/quad-storage
Plugin for macro-, mini-quad (quads) to save data in simple local storage using Web Storage API in WASM and local file on a native platforms.
https://github.com/optozorax/quad-storage
Last synced: about 2 months ago
JSON representation
Plugin for macro-, mini-quad (quads) to save data in simple local storage using Web Storage API in WASM and local file on a native platforms.
- Host: GitHub
- URL: https://github.com/optozorax/quad-storage
- Owner: optozorax
- License: apache-2.0
- Created: 2021-07-31T16:00:58.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T13:26:25.000Z (4 months ago)
- Last Synced: 2024-09-08T14:58:10.369Z (4 months ago)
- Language: Rust
- Size: 910 KB
- Stars: 14
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-quads - quad-storage - to save data in persistent storage using Web Storage API. (Libraries / Libraries: Plugins)
README
# quad-storage
[![Docs](https://docs.rs/quad-storage/badge.svg?version=0.1.0)](https://docs.rs/quad-storage/0.1.0/quad_url/)
[![Crates.io version](https://img.shields.io/crates/v/quad-storage.svg)](https://crates.io/crates/quad-storage)This is the crate to save data in persistent local storage in miniquad/macroquad environment. In WASM the data persists even if tab or browser are closed. To achieve that [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) is used. To save data on native platforms, data is just saved to the local file named `local.data`.
[Web demo.](https://optozorax.github.io/quad-storage/)
# Code example
```rust
let storage = &mut quad_storage::STORAGE.lock().unwrap();
storage.set("test", "value");
let value = storage.get("test").unwrap();
dbg!(value);
```# Usage
Add this to your `Cargo.toml` dependencies:
```text
quad-storage = "0.1.0"
```
# Usage in WASM
Add file [`quad-storage/js/quad-storage.js`](https://github.com/optozorax/quad-storage/blob/master/js/quad-storage.js) to your project.Add file [`sapp-jsutils/js/sapp_jsutils.js`](https://github.com/not-fl3/sapp-jsutils/blob/master/js/sapp_jsutils.js) file to your project.
Add this lines after loading of `gl.js` and before loading of your wasm in your `index.html`:
```html```
Done! Now you can use this crate.