How dropbox/dropbox-sdk-rust works
Project Type and Purpose
• This is a Rust library (“crate”) that provides Dropbox API v2 bindings, with code generated from the official spec via the Stone framework.
• It supports both sync and async routes, pluggable HTTP clients, and ships with default clients and OAuth2 helpers.
File‐Structure Analysis
• Top‐level directories:
• src/ ← core SDK modules + generated code
• generator/ ← Python scripts and templates to drive code generation
• examples/ ← sample programs exercising the SDK
• tests/ ← integration and generated serialization tests
• dropbox-api-spec/ ← API spec submodule (input to generator)
• stone/ ← Stone code‐generation engine submodule
• Key modules in src/:
• client_trait.rs & async_client_trait.rs ← HTTP‐client interfaces
• default_client*.rs ← built-in clients (ureq/rustls, reqwest)
• oauth2.rs ← helper code for OAuth2 flows
• error.rs ← error types & handling
• generated/ ← auto‐generated routes (sync/async) & types
• Build & deployment files: Cargo.toml, feature flags for sync/async/default_client, generate.py, update_spec.py.
README Insights
• Describes two main workflows:
1. Code Generation (generate.py + stone + dropbox-api-spec → src/generated + tests)
2. Runtime Usage (user’s code → instantiate HttpClient → call SDK routes → HTTP calls to Dropbox)
• Explains feature flags, authentication types, default clients, testing approach.
Diagramming the Architecture
a. Main Components
• Code‐Generation Pipeline
– dropbox-api-spec (spec JSON)
– stone engine (templates + python)
– generate.py & generator/*.py → src/generated & tests
• Core SDK Runtime
– client_trait (HttpClient, marker traits)
– async_client_trait
– error.rs
– oauth2.rs
• Default HTTP Clients
– sync: ureq + rustls (default_client.rs)
– async: reqwest (default_async_client.rs)
• Generated Routes & Types
– sync_routes & async_routes modules
– types module (structs, enums)
• User Code
– examples/ and any consuming application
• External Services
– Dropbox API endpoints (HTTPS)
b. Relationships & Data Flow
1. Developer runs generate.py → stone + spec → generated Rust code & tests
2. Cargo build/test pulls in src/** modules + generated code
3. At runtime, user code selects a client (implements HttpClient or uses default)
4. User code calls dropbox_sdk::<sync|async>_routes::<namespace>::function(...)
5. Route implementation serializes params → client.send(request) → HTTP over TLS → Dropbox API → JSON response → deserialized into generated types → returned to user
c. Architectural Patterns & Principles
• Code‐generation separates spec → source, keeping generated code in src/generated
• Trait abstraction (HttpClient) to decouple HTTP layer
• Feature flags for modular inclusion of sync/async and namespace subsets
• Sync façade built on top of async traits for code reuse
d. Key Technologies
• Rust & Cargo (features, modules)
• Python + Stone framework for generation
• ureq + rustls, reqwest for HTTP
• serde‐style manual serialization