liveBook · Manning

In-memory database

As explained in Rust Servers, Services, and Apps

An in-memory data store is a data-storage component that keeps its working data in main memory rather than relying primarily on persistent storage.

An in-memory data store holds the course records used by the EzyTutors REST APIs. The service uses it instead of a database. section 3.1 section 3.0

use super::models::Course;
use std::sync::Mutex;
pub struct AppState {
    pub health_check_response: String,
    pub visit_count: Mutex<u32>,
    pub courses: Mutex<Vec<Course>>,  #1
}

The application state holds courses in a mutex-protected vector, allowing the service to share its store. section 3.2.3

The vector starts empty when the application state is created. The course data model is defined before the APIs that use the store. section 3.2.3 section 3.2.3

How Rust Servers, Services, and Apps covers it

How deep it goes
Shows a mutex-protected course vector in application state and its empty initialization.
Examples
Uses an initially empty Mutex<Vec<Course>> as the course store.
What you can do after
Build it from scratch as shared Actix state containing a mutex-protected course collection.
How it connects
Connects course REST APIs to Actix application state and Rust mutex-protected collections.

Also explained in

Compare how 5 books explain in-memory database →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.