Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But still- at a language semantics level, values can't have multiple owners, and String couldn't implement Copy just for this one case. So how does this reconcile with the borrow-checker?

Or can consts have multiple owners since they're immutable and have a static lifetime? Is this just the first case of a non-Copy being const, so the question has never come up before?



Ah, I get your question now, I thought you were talking about const functions. Well, const values in Rust are funny things, they're not linked into the executable, they don't have an address or a lifetime. That confused me too for a while. They're purely a shortcut for a value expression, not that different from a #define in C.

Statics, in contrast, have a storage location and a static lifetime.

Compare:

  const CONST_STRING: String = String::new();
  static STATIC_STRING: String = String::new();

  fn main() {
      let x: String = CONST_STRING;  // fine
      let y: String = STATIC_STRING; // error: cannot move out of static item
  }


Oh. I think I didn't realize both existed; I'd only used statics before (and knew about const functions), but didn't know about const expressions.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: