WeSearch

My Tiny Rust Utils, Part 2: helpers.rs

·3 min read · 0 reactions · 0 comments · 3 views
My Tiny Rust Utils, Part 2: helpers.rs

A humble little helpers file: caller-aware errors, JSON conversion, and one tiny tracked error type.

Original article
DEV.to (Top)
Read full at DEV.to (Top) →
Opening excerpt (first ~120 words) tap to expand

try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3906362) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } icsboyx Posted on Apr 30 My Tiny Rust Utils, Part 2: helpers.rs #rust #errors #serde #tutorial A Small Rust Utils Folder (4 Part Series) 1 My Tiny Rust Utils, Part 1: macros.rs 2 My Tiny Rust Utils, Part 2: helpers.rs 3 My Tiny Rust Utils, Part 3: save_load.rs 4 My Tiny Rust Utils, Part 4: web.rs After logging, the next kind of repetition that starts bothering me is usually this: adding context to errors converting typed values into JSON request bodies Neither of those is dramatic…

Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from DEV.to (Top)