3.2 KiB
3.2 KiB
Rust Workspace
All Rust code lives under crates/. The workspace is defined in Cargo.toml at the repo root.
Code Style
- Two spaces for indentation (not four)
- No minimum supported Rust version; use latest stable features freely
- Never use
println!oreprintln!outside of tests; uselogcrate macros instead - Use
anyhow::Result/AnyhowResultfor fallible functions in application code - Fields that are optional use the
maybe_prefix:maybe_creator_user_token - When two crates export the same type name, alias with a suffix:
use foo::Bar as BarFoo; - Prefer
useimports over inline fully-qualified paths; only qualify inline for true one-offs or std prelude collisions (Result,Option,Error)
File Layout
Organize for top-to-bottom reading. Important things first, details later.
- Constants at the top (after imports)
- Primary public type (the main struct/enum the file defines)
- Supporting types below the primary type
- API types in order: Request, Response, Error
implblocks after their type definitions- Constructors first, then public methods, then private helpers
- Callers above callees — follow the call chain downward
Test Layout
Within #[cfg(test)] mod tests { ... }:
- Imports
- Constants (test IDs, URLs, fixture data) — small context that tests reference
- Test functions or sub-modules grouped by category
- Helper functions (builders, pipeline runners, assertions)
Constants provide small context up front. Test cases come next so engineers see what is tested before how the helpers work.
Group related tests into sub-modules (mod pricing_tests { ... }) when a category has 2+
tests. Don't wrap a single test in its own module. Keep nesting to two levels max. Shared
helpers go in the parent mod tests so sub-modules can use super::*.
Building
- Most crates:
cargo check -p {crate_name}orcargo test -p {crate_name} - Crates using SQLx (eg.
sqlite_database):SQLX_OFFLINE=true cargo check -p {crate_name}
Key Crates
artcraftx(desktop) — Tauri desktop approuter— provider routing for image/video generation (Artcraft, Fal, Seedance2Pro)artcraft_client— HTTP client for the Artcraft/Storyteller API, including the API type definitions (artcraft_client::api_defs), enum variants stored as strings (artcraft_client::enums), and opaque server-minted identifier tokens with Stripe-like prefixes (artcraft_client::tokens, e.g.user_,jinf_)seedance2pro_client— HTTP client for the Kinovi/Seedance2Pro video generation servicecore_types— highest-level shared types:GenerationSource, the desktop app's own IDs (e.g.credential_{ulid})sqlite_database— SQLx queries + embedded migrations for the desktop app's local task databaselocal_files_database— separate SQLite DB (runtime SQLx queries, no macros): BLAKE3 content-hash index of local files + thumbnail accountingthumbnails— pure-Rust thumbnail generation: images viaimage, H.264 MP4 first-frame JPEG + ~1s animated WebP viamp4/openh264/webp-animationfile_hashing— streaming BLAKE3 content hashingsqlite_identifiers— enums and IDs used in sqlite queries as enums or keys