3 releases

Uses new Rust 2024

0.1.4 Jul 21, 2025
0.1.1 May 7, 2025
0.1.0 Oct 4, 2024

#1838 in Database interfaces

Download history 86/week @ 2025-12-24 58/week @ 2025-12-31 41/week @ 2026-01-07 50/week @ 2026-01-14 98/week @ 2026-01-21 92/week @ 2026-01-28 106/week @ 2026-02-04 48/week @ 2026-02-11 82/week @ 2026-02-18 78/week @ 2026-02-25 52/week @ 2026-03-04 93/week @ 2026-03-11 91/week @ 2026-03-18 52/week @ 2026-03-25 56/week @ 2026-04-01 83/week @ 2026-04-08

286 downloads per month
Used in 49 crates (8 directly)

MPL-2.0 license

35KB
546 lines

MoosicBox Profiles

A simple profile name management system for the MoosicBox ecosystem, providing basic profile name storage and validation for request handling.

Features

  • Profile Name Storage: Add, remove, and retrieve profile names
  • Profile Validation: Verify profile names exist before processing requests
  • Thread-Safe Operations: Safe concurrent access to profile data
  • API Integration: Extract profile names from HTTP headers and query parameters

Installation

Add this to your Cargo.toml:

[dependencies]
moosicbox_profiles = "0.1.1"

Usage

Basic Profile Management

use moosicbox_profiles::PROFILES;

fn main() {
    // Add a profile
    PROFILES.add("user123".to_string());

    // Check if profile exists
    if let Some(profile) = PROFILES.get("user123") {
        println!("Profile found: {}", profile);
    }

    // Get all profile names
    let all_profiles = PROFILES.names();
    println!("All profiles: {:?}", all_profiles);

    // Remove a profile
    PROFILES.remove("user123");
}

API Integration

use moosicbox_profiles::api::{ProfileName, ProfileNameUnverified};
use actix_web::{web, HttpResponse, Result};

// Extract verified profile name from request
async fn handler(profile: ProfileName) -> Result<HttpResponse> {
    let profile_name: String = profile.into();
    Ok(HttpResponse::Ok().json(format!("Hello, {}", profile_name)))
}

// Extract unverified profile name from request
async fn handler_unverified(profile: ProfileNameUnverified) -> Result<HttpResponse> {
    let profile_name: String = profile.into();
    // Profile name exists in request but may not be registered
    Ok(HttpResponse::Ok().json(format!("Profile: {}", profile_name)))
}

API Features

The package provides request extractors for Actix Web:

  • ProfileName: Extracts and validates profile names from requests
  • ProfileNameUnverified: Extracts profile names without validation
  • Header Support: Reads from moosicbox-profile header
  • Query Parameter Support: Reads from moosicboxProfile query parameter

Profile names are extracted in this order of precedence:

  1. Query parameter moosicboxProfile
  2. HTTP header moosicbox-profile

Error Handling

  • Missing profile information returns 400 Bad Request
  • Non-existent profiles return 400 Bad Request
  • Invalid header values return 400 Bad Request

Thread Safety

All operations are thread-safe using RwLock for concurrent access to the profile storage.

Dependencies

~2–15MB
~137K SLoC