{"id":13503120,"url":"https://github.com/TheNeikos/rustbreak","last_synced_at":"2025-03-29T13:30:45.915Z","repository":{"id":44953040,"uuid":"70986930","full_name":"TheNeikos/rustbreak","owner":"TheNeikos","description":"A simple, fast and easy to use self-contained single file storage for Rust","archived":true,"fork":false,"pushed_at":"2022-01-16T12:16:23.000Z","size":5412,"stargazers_count":393,"open_issues_count":7,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-14T07:34:03.174Z","etag":null,"topics":["bincode","database","daybreak","file","hashmap","ron","rust","rustbreak","storage","yaml"],"latest_commit_sha":null,"homepage":"https://docs.rs/rustbreak/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheNeikos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-15T12:37:43.000Z","updated_at":"2024-04-12T15:18:15.000Z","dependencies_parsed_at":"2022-08-12T11:40:36.063Z","dependency_job_id":null,"html_url":"https://github.com/TheNeikos/rustbreak","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNeikos%2Frustbreak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNeikos%2Frustbreak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNeikos%2Frustbreak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNeikos%2Frustbreak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheNeikos","download_url":"https://codeload.github.com/TheNeikos/rustbreak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246093188,"owners_count":20722402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bincode","database","daybreak","file","hashmap","ron","rust","rustbreak","storage","yaml"],"created_at":"2024-07-31T22:02:37.890Z","updated_at":"2025-03-29T13:30:45.595Z","avatar_url":"https://github.com/TheNeikos.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"Rustbreak\n=========\n\n[![Build Status](https://travis-ci.org/TheNeikos/rustbreak.svg?branch=master)](https://travis-ci.org/TheNeikos/rustbreak)\n[![Crates Link](https://img.shields.io/crates/v/rustbreak.svg)](https://crates.io/crates/rustbreak)\n\n**[Documentation][doc]**\n\nRustbreak is an [Daybreak] inspired self-contained file\ndatabase. It is meant to be fast and simple to use. You add it to your\napplication and it should just work for you. The only thing you will have to\ntake care of is saving.\n\nWhen to use it\n--------------\n\nThis library started out because of a need to be able to quickly write an\napplication in rust that needed some persistence while still being able to write\narbitrary data to it.\n\nIn Ruby there is [Daybreak] however for Rust there was no similar crate, until\nnow!\n\nWhen not to use it\n------------------\n\nRustbreak makes several trade-offs to be easy to use and extend, so knowing of these drawbacks is important if \nyou wish to use the library:\n\n- The Database needs to fit into memory (Rustbreak cannot do partial loads/saves, so if the Database exceeds your available memory you will run OOM)\n- Not all backends support atomic saves, so if your program crashes while it is saving you might save incomplete data (Notably only `PathBackend` supports atomic saves)\n\nFeatures\n--------\n\n- Simple To Use, Fast, Secure\n- Threadsafe\n- Serde compatible storage (ron, bincode, or yaml included)\n\nQuickstart\n----------\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies.rustbreak]\nversion = \"2\"\nfeatures = [\"ron_enc\"] # You can also use \"yaml_enc\" or \"bin_enc\"\n                       # Check the documentation to add your own!\n```\n\n```rust\nextern crate rustbreak;\nuse std::collections::HashMap;\nuse rustbreak::{MemoryDatabase, deser::Ron};\n\nfn main() -\u003e rustbreak::Result\u003c()\u003e {\n    let db = MemoryDatabase::\u003cHashMap\u003cu32, String\u003e, Ron\u003e::memory(HashMap::new())?;\n\n    println!(\"Writing to Database\");\n    db.write(|db| {\n        db.insert(0, String::from(\"world\"));\n        db.insert(1, String::from(\"bar\"));\n    });\n\n    db.read(|db| {\n        // db.insert(\"foo\".into(), String::from(\"bar\"));\n        // The above line will not compile since we are only reading\n        println!(\"Hello: {:?}\", db.get(\u00260));\n    })?;\n\n    Ok(())\n}\n```\n\nUsage\n-----\n\nUsage is quite simple:\n\n- Create/open a database using one of the Database constructors:\n    - Create a `FileDatabase` with `FileDatabase::from_path`.\n    - Create a `MemoryDatabase` with `MemoryDatabase::memory`.\n    - Create a `MmapDatabase` with `MmapDatabase::mmap` or `MmapDatabase::mmap_with_size` with `mmap` feature.\n    - Create a `Database` with `Database::from_parts`.\n- `Write`/`Read` data from the Database\n- Don't forget to run `save` periodically, or whenever it makes sense.\n    - You can save in parallel to using the Database. However you will lock\n      write acess while it is being written to storage.\n\n```rust\n# use std::collections::HashMap;\nuse rustbreak::{MemoryDatabase, deser::Ron};\n\nlet db = MemoryDatabase::\u003cHashMap\u003cString, String\u003e, Ron\u003e::memory(HashMap::new(), Ron);\n\nprintln!(\"Writing to Database\");\ndb.write(|db| {\n    db.insert(\"hello\".into(), String::from(\"world\"));\n    db.insert(\"foo\".into(), String::from(\"bar\"));\n});\n\ndb.read(|db| {\n    // db.insert(\"foo\".into(), String::from(\"bar\"));\n    // The above line will not compile since we are only reading\n    println!(\"Hello: {:?}\", db.get(\"hello\"));\n});\n```\n\n## Encodings\n\nThe following parts explain how to enable the respective features. You can also\nenable several at the same time.\n\n### Yaml\n\nIf you would like to use yaml you need to specify `yaml_enc` as a feature:\n\n```toml\n[dependencies.rustbreak]\nversion = \"2\"\nfeatures = [\"yaml_enc\"]\n```\n\nYou can now use `rustbreak::deser::Yaml` as deserialization struct.\n\n### Ron\n\nIf you would like to use [`ron`](https://github.com/ron-rs/ron) you need to\nspecify `ron_enc` as a feature:\n\n```toml\n[dependencies.rustbreak]\nversion = \"2\"\nfeatures = [\"ron_enc\"]\n```\n\nYou can now use `rustbreak::deser::Ron` as deserialization struct.\n\n### Bincode\n\nIf you would like to use bincode you need to specify `bin_enc` as a feature:\n\n```toml\n[dependencies.rustbreak]\nversion = \"2\"\nfeatures = [\"bin_enc\"]\n```\n\nYou can now use `rustbreak::deser::Bincode` as deserialization struct.\n\n\n[doc]:http://neikos.me/rustbreak/rustbreak/index.html\n[Daybreak]:https://propublica.github.io/daybreak/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheNeikos%2Frustbreak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTheNeikos%2Frustbreak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTheNeikos%2Frustbreak/lists"}