Skip to content
masterclass Buddy

Rust · Class

Cow

Rust's Cow is a clone-on-write smart pointer. It reads borrowed data without copying and creates owned data only when mutation or ownership is needed.

Last updated

Since
1.0.0

Syntax

pub enum Cow<'a, B> where B: 'a + ToOwned + ?Sized {
    Borrowed(&'a B),
    Owned(<B as ToOwned>::Owned),
}

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • Borrowed
  • Owned
  • ToOwned
  • Borrow
  • Deref
  • Rc::make_mut
  • Arc::make_mut
  • to_mut

Source: Cow in std::borrow - Rust. Checked 2026-11-03.