From ef7a3a47c4db83e07032ac985fac7904ad74ae0f Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Tue, 17 Mar 2026 09:54:33 +0400 Subject: [PATCH] Disallow mut ref to inner Vec for NEVec, allow ref and mut ref to slice Allowing mut access to inner Vec much allows breaking the non-emptyness invariant. --- src/vector.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/vector.rs b/src/vector.rs index 00084a4..02e3cfc 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1,10 +1,10 @@ //! Non-empty Vectors. +use crate::Singleton; use crate::iter::FromNonEmptyIterator; use crate::iter::IntoNonEmptyIterator; use crate::iter::NonEmptyIterator; use crate::slice::NEChunks; -use crate::Singleton; use core::fmt; use std::cmp::Ordering; use std::fmt::Debug; @@ -1027,8 +1027,14 @@ impl AsRef> for NEVec { } } -impl AsMut> for NEVec { - fn as_mut(&mut self) -> &mut Vec { +impl AsRef<[T]> for NEVec { + fn as_ref(&self) -> &[T] { + self.inner.as_ref() + } +} + +impl AsMut<[T]> for NEVec { + fn as_mut(&mut self) -> &mut [T] { self.inner.as_mut() } }