Understanding Rust's Cow Smart Pointer Through Source Code Analysis

Rust's Cow (Copy-on-Write) is a smart pointer that enables lazy cloning. It's useful when data might be mutated or ownership might change, but you want to avoid unnecessary copies—ideal for read-heavy, write-rare scenarios. pub enum Cow<'a, B: ?Sized + 'a> where B: ToOwned, { /// Borrowed data. Borrowed(&'a B), /// Own ...

Posted on Sun, 16 Aug 2026 16:40:05 +0000 by vadercole

Building a Custom String Class in C++

A custom string class typically wraps a dynamically alocated character array along with size and capacity tracking. The following implementation lives inside a dedicated namespace to avoid collisions with the standard library. namespace custom { class string { private: char* _data; size_t _len; size_t _cap; ...

Posted on Fri, 08 May 2026 01:30:05 +0000 by BRUUUCE