Re: [PATCH v3 1/2] rust: non_empty: add NonEmpty
From: Miguel Ojeda
Date: Wed Oct 14 2026 - 07:55:47 EST
On Wed, Oct 14, 2026 at 10:30 AM Lorenzo Delgado <lnsdev@xxxxxxxxx> wrote:
>
> +/// A container that can report whether it holds any element.
> +///
> +/// The result must not change while the container is only reachable through a shared reference.
> +///
> +/// Unsafe code may only rely on the result for a container type whose implementation it trusts,
> +/// such as the ones in this module, since a safe implementation can return anything.
> +pub trait IsEmpty {
> + /// Returns `true` if the container holds no element.
> + fn is_empty(&self) -> bool;
> +}
Do we need this to be a safe trait? If it is unsafe, then we can
simplify the invariant and more easily think about the type, like
other `Non*`s, no?
Thanks!
Cheers,
Miguel