Skip to content

Blog

My Experience of Using Rust

Advantages Error handling is a step ahead of Go, more robust. A more robust service is less worrisome. Error declaration (very intuitive) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #[derive(Debug, thiserror::Error)] pub enum InfoFetchError { #[error("Failed to send HTTP request: {0}")] SendHttpRequestError(reqwest::Error), #[error("HTTP response error: {0}")] HttpResponseError(reqwest::Error), #[error("HTTP response body error: {0}")] HttpResponseBodyError(reqwest::Error), #[error("Script element not found")] NoScriptError, #[error("Script processing error")] ProcessScriptError, #[error("JSON parsing error: {0}")] JsonParseError(#[from] serde_json::Error), #[error("No PlayItem")] NoPlayItemError, } Error handling (very robust, forces error checking) 1 2 3 4 5 6 7 8 9 10 let resp = req .send() .await .map_err(|e| InfoFetchError::SendHttpRequestError(e))? .error_for_status() .map_err(|e| InfoFetchError::HttpResponseError(e))?; let text = resp .text() .await .map_err(|e| InfoFetchError::HttpResponseBodyError(e))?; Pattern matching may have a bit of a learning curve, but it is very powerful once mastered.

Read more →

TypeScript Configuration

tsconfig.json 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 { "include": ["src", "*.config.ts"], "exclude": ["dist", "node_modules"], "compilerOptions": { // Type Checking "strict": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "exactOptionalPropertyTypes": true, "noFallthroughCasesInSwitch": true, "noImplicitOverride": true, "noImplicitReturns": true, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true, "noUnusedLocals": true, "noUnusedParameters": true, // Modules "types": ["vite/client"], "module": "esnext", "moduleResolution": "bundler", "allowImportingTsExtensions": true, "noUncheckedSideEffectImports": true, // Emit "noEmit": true, // JavaScript Support "allowJs": false, // Interop Constraints "erasableSyntaxOnly": true, "isolatedModules": true, "verbatimModuleSyntax": true, // Language and Environment "lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"], "target": "esnext", // Completeness "skipLibCheck": true, }, } In addition, the official TS documentation does not recommend paths, but recommends Node Subpath Imports instead.

Read more →

Use C++ Modules and import std

macOS + Clang Warning Clang version must be at least 19. Install tools 1 2 xcode-select --install brew install llvm cmake ninja Note

Read more →