6 releases

0.3.0 Jan 11, 2023
0.2.0 Mar 26, 2021
0.1.1 Nov 4, 2020

#315 in HTTP server

Download history 23/week @ 2023-11-03 27/week @ 2023-11-10 22/week @ 2023-11-17 44/week @ 2023-11-24 38/week @ 2023-12-01 28/week @ 2023-12-08 28/week @ 2023-12-15 33/week @ 2023-12-22 18/week @ 2023-12-29 17/week @ 2024-01-05 25/week @ 2024-01-12 26/week @ 2024-01-19 50/week @ 2024-01-26 35/week @ 2024-02-02 42/week @ 2024-02-09 158/week @ 2024-02-16

288 downloads per month
Used in 4 crates


1.5K SLoC


Actix storage is a simple wrapper around some key-value storages to provide basic operations without knowing the backend in advance.


Actix-storage is meant to be used alongside one the implementer crates, ex:

# Cargo.toml
actix-storage = "0.3.0"
actix-storage-hashmap = "0.3.0"

Or you want to use the serde based methods for typed information:

actix-storage = {version = "0.3.0", features=["serde-json"]}


After you picked an implementer:

use actix_storage::{Storage, Format};
use actix_storage_hashmap::HashMapActor;
use actix_web::{App, HttpServer};

async fn main() -> std::io::Result<()> {
   // Intialize the implementer according to its docs
   let store = HashMapActor::start_default();

   // Give it to the Storage struct
   let storage = Storage::build().expiry_store(store).finish();

   // Or if it doesn't support expiring functionality
   // it will give errors if those methods are called
   let storage = Storage::build().store(store).finish();

   // It is also possible to feed a seprate expiry,
   // as long as it works on the same storage backend
   let storage = Storage::build().expiry(expiry).finish();

   // It is also possible to add a format to directly
   // set and get values using serde.
   let storage = Storage::build().store(expiry).format(Format::Json).finish();

   // Store it in you application state with actix_web::App.app_data
   let server = HttpServer::new(move || {

And later in your handlers

async fn index(storage: Storage) -> Result<String, Error>{
   storage.set_bytes("key", "value").await;
   let val = storage.get_bytes("key").await?.unwrap_or_default();

   // Or if you defined a serde format
   let number: i32 = 5
   storage.set("number", number);
   let x: i32 = storage.get("number");

      .map_err(|err| error::ErrorInternalServerError("Storage error"))?.to_string())


actix-storage-hashmap docs.rs docs

actix-storage-dashmap docs.rs docs

actix-storage-sled docs.rs docs

actix-storage-redis docs.rs docs


It can be usefull when:

  1. You don't know which key-value database you'll need later.
  2. You can't afford the long time compilation of some dbs while developing.
    • hashmap store compiles pretty fast
  3. You're writing an actix-web extension library and need to support multiple storage backends.

Why not?

If you really care about every drop of your application performance then actix-storage may not be for you, as it uses dynamic dispatching internally.


There are bunch of examples in the examples folder, very basic ones thought, but it will give you the idea.


This project is licensed under either of

at your option.


~539K SLoC