This document outlines the step-by-step plan to migrate the C# Qobuz API library to Rust, preserving all functionality while adhering to Rust's best practices.
The C# Qobuz API library provides access to Qobuz's music streaming API, including authentication, content retrieval (albums, artists, tracks), search functionality, user favorites management, and streaming URL generation. The migration to Rust will maintain the same functionality while leveraging Rust's memory safety, performance, and concurrency features.
-
Initialize Rust Project
- Create a new Rust library project:
cargo new qobuz-api-rust - Configure
Cargo.tomlwith necessary dependencies - Relevant C# files:
QobuzApiSharp/QobuzApiSharp.csproj
- Create a new Rust library project:
-
Configure Dependencies
reqwestfor HTTP client functionalitytokiofor async runtimeserdeandserde_jsonfor serialization/deserializationmd5for MD5 hashingregexfor regex operationsthiserrorfor error handlingchronofor date/time handling- Relevant C# files:
QobuzApiSharp/QobuzApiSharp.csproj,QobuzApiSharp/packages.config
-
Create Error Types
- Define error enum using
thiserror:ApiErrorResponse { code: String, message: String, status: String }ApiResponseParseError { content: String, source: Box<dyn std::error::Error> }QobuzApiInitializationError { message: String }
- Relevant C# files:
QobuzApiSharp/Api/Exceptions/ApiErrorResponseException.cs,QobuzApiSharp/Api/Exceptions/ApiResponseParseErrorException.cs,QobuzApiSharp/Api/Exceptions/QobuzApiInitializationException.cs
- Define error enum using
-
Create Basic Models
QobuzApiStatusResponsewithcode,message, andstatusfields- Basic content models (Artist, Album, Track, User, etc.)
- Relevant C# files:
QobuzApiSharp/Api/Models/QobuzApiStatusResponse.cs,QobuzApiSharp/Api/Models/Content/General/Artist.cs,QobuzApiSharp/Api/Models/Content/Album/Album.cs,QobuzApiSharp/Api/Models/Content/Track/Track.cs,QobuzApiSharp/Api/Models/User/User.cs
-
Implement JSON Serialization
- Use
serdederive macros for all models - Implement custom deserializers where needed (similar to C# converters)
- Relevant C# files:
QobuzApiSharp/Api/Converters/TrackIdsConverter.cs,QobuzApiSharp/Api/Converters/MostPopularContentConverter.cs,QobuzApiSharp/Api/Service/QobuzApiHelper.cs
- Use
-
Create Utilities Module
- MD5 utilities for hashing
- Query string builder
- Time utilities for Unix timestamps
- Relevant C# files:
QobuzApiSharp/Api/Utilities/MD5Utilities.cs
-
Implement API Helper Functions
- Web player app ID/secret extraction
- File URL signature generation
- HTTP response deserialization
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiHelper.cs,QobuzApiSharp/Api/QobuzApiConstants.cs
-
Create Qobuz API Service Structure
- Define
QobuzApiServicestruct with:app_id: Stringapp_secret: Stringuser_auth_token: Option<String>client: reqwest::Client
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiService.cs
- Define
-
Implement HTTP Request Handling
- Async methods for sending requests
- Error handling for API responses
- Request signature generation for protected endpoints
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiService.cs,QobuzApiSharp/Api/Service/QobuzApiHelper.cs
-
Implement User Authentication
login_with_emailmethodlogin_with_usernamemethodlogin_with_tokenmethodreset_passwordmethods- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.User.cs,QobuzApiSharp/Api/Models/User/Login.cs
-
Session Management
- Token storage and retrieval
- Authentication header management
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiService.cs,QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.User.cs
-
Album Endpoints
get_albummethodsearch_albumsmethod- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Album.cs,QobuzApiSharp/Api/Models/Content/Album/Album.cs
-
Artist Endpoints
get_artistmethodsearch_artistsmethod- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Artist.cs,QobuzApiSharp/Api/Models/Content/General/Artist.cs
-
Track Endpoints
get_trackmethodget_track_file_urlmethod (with signature generation)search_tracksmethod- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Track.cs,QobuzApiSharp/Api/Models/Content/Track/Track.cs,QobuzApiSharp/Api/Models/Content/Track/FileUrl.cs
-
Playlist Endpoints
get_playlistmethodsearch_playlistsmethod- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Playlist.cs,QobuzApiSharp/Api/Models/Content/Playlist/Playlist.cs
-
Other Content Endpoints
- Article endpoints
- Label endpoints
- Story endpoints
- Catalog search
- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Article.cs,QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Label.cs,QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Story.cs,QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Catalog.cs
-
Favorite Management
add_user_favoritesmethoddelete_user_favoritesmethodget_user_favorite_idsmethodget_user_favoritesmethod- Relevant C# files:
QobuzApiSharp/Api/Service/Endpoints/QobuzApiService.Favorite.cs,QobuzApiSharp/Api/Models/Content/General/UserFavorites.cs,QobuzApiSharp/Api/Models/Content/General/UserFavoritesIds.cs
-
Additional User Features
- User profile retrieval
- Subscription information
- Relevant C# files:
QobuzApiSharp/Api/Models/User/User.cs,QobuzApiSharp/Api/Models/User/Subscription.cs
-
Web Player Integration
- Implement fetching app ID/secret from web player
- Bundle.js parsing with regex
- Base64 decoding and string manipulation
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiHelper.cs,QobuzApiSharp/Api/QobuzApiConstants.cs
-
Specialized Converters
- Implement custom deserializers for inconsistent API responses
- Handle the TrackIdsConverter functionality for mixed JSON types
- Relevant C# files:
QobuzApiSharp/Api/Converters/TrackIdsConverter.cs,QobuzApiSharp/Api/Converters/MostPopularContentConverter.cs
-
Unit Tests
- Test all model serialization/deserialization
- Test utility functions
- Test API helper functions
- Relevant C# files: All model files, utility files, and helper files
-
Integration Tests
- Test API endpoints with mock responses
- Test authentication flows
- Test error handling
- Relevant C# files: All endpoint files in
QobuzApiSharp/Api/Service/Endpoints/
-
Functional Verification
- Verify all functionality matches C# implementation
- Test with real Qobuz API (if possible with test credentials)
- Relevant C# files: All files in the codebase for reference
-
Documentation
- Add comprehensive Rust documentation comments
- Create examples for common use cases
- Document error handling patterns
- Relevant C# files: All files in the codebase for reference
-
Rust Best Practices Implementation
- Proper error handling with
Result<T, E>types - Memory safety without garbage collection
- Use of async/await for I/O operations
- Proper ownership and borrowing patterns
- Implement
DisplayandDebugtraits where appropriate - Relevant C# files: All files in the codebase for reference
- Proper error handling with
-
Performance Optimizations
- Connection pooling with reqwest
- Efficient JSON parsing
- Proper async execution patterns
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiService.cs,QobuzApiSharp/Api/Service/QobuzApiHelper.cs
- Use
Stringinstead of&strfor owned data in structs - Implement proper ownership patterns
- Avoid unnecessary cloning
- Relevant C# files: All model files for reference
- Use
tokio::taskfor concurrent operations - Implement proper async/await patterns
- Handle async error propagation correctly
- Relevant C# files:
QobuzApiSharp/Api/Service/QobuzApiService.cs
- Use
thiserrorfor comprehensive error types - Implement proper error chaining
- Provide meaningful error messages
- Relevant C# files:
QobuzApiSharp/Api/Exceptions/ApiErrorResponseException.cs,QobuzApiSharp/Api/Exceptions/ApiResponseParseErrorException.cs,QobuzApiSharp/Api/Exceptions/QobuzApiInitializationException.cs
- Leverage Rust's type system for API safety
- Use
Option<T>for nullable fields - Use
Result<T, E>for fallible operations - Implement proper validation for API inputs
- Relevant C# files: All model files for reference
The Rust implementation will maintain the same public API contract as the C# version:
- Same method names and signatures (adapted to Rust conventions)
- Same parameter types and return types
- Same error handling patterns
- Same authentication mechanisms
- Same functionality for all endpoints
- Relevant C# files: All endpoint files in
QobuzApiSharp/Api/Service/Endpoints/
- Implement comprehensive unit tests for all modules
- Use mock HTTP servers for API testing
- Test error scenarios and edge cases
- Verify JSON serialization/deserialization correctness
- Performance testing to ensure Rust benefits are realized
- Relevant C# files: All files in the codebase for reference
- Package as a Rust crate on crates.io
- Provide clear usage examples
- Document installation and setup requirements
- Include compatibility notes for different Rust versions
- Relevant C# files:
QobuzApiSharp/QobuzApiSharp.csproj,QobuzApiSharp/QobuzApiSharp.nuspec