When should we mark our functions unsafe?

Nope! Internals is about developing rust itself, users is about using Rust. This question is a perfect post here.

Any time that calling the function could introduce memory unsafety. "Memory safety" is the absence of "data races." Data races are: Race Condition vs. Data Race – Embedded in Academia

A data race happens when there are two memory accesses in a program where both:

  • target the same location
  • are performed concurrently by two threads
  • are not reads
  • are not synchronization operations

In some sense yes, and in some sense no. Exposing safe interfaces is preferred, but sometimes, you have to expose something that's unsafe. That's not an inherently bad thing.

Yup! So they'd still be unsafe. It's just a fact of life.

2 Likes