#[cfg(feature = "alloc")]
use devela::RangeFull;
#[doc = crate::_tags!(maybe lifetime)]
#[doc = crate::_doc_location!("sys/mem")]
#[derive(Debug, PartialEq)]
pub enum Backing<'a> {
Buf(&'a mut [u8]),
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
Alloc,
}
impl Backing<'_> {
#[inline(always)]
pub const fn is_buf(&self) -> bool {
#[cfg(not(feature = "alloc"))]
return false;
#[cfg(feature = "alloc")]
matches!(self, Self::Alloc)
}
#[inline(always)]
pub const fn is_alloc(&self) -> bool {
matches!(self, Self::Buf(_))
}
}
impl<'a> From<&'a mut [u8]> for Backing<'a> {
fn from(buf: &'a mut [u8]) -> Self {
Self::Buf(buf)
}
}
impl<'a, const LEN: usize> From<&'a mut [u8; LEN]> for Backing<'a> {
fn from(buf: &'a mut [u8; LEN]) -> Self {
Self::Buf(buf)
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(nightly_doc, doc(cfg(feature = "alloc")))]
impl<'a> From<RangeFull> for Backing<'a> {
fn from(_: RangeFull) -> Self {
Self::Alloc
}
}