beef/
wide.rs

1use crate::traits::Capacity;
2use core::num::NonZeroUsize;
3
4/// Compact three word `Cow` that puts the ownership tag in capacity.
5/// This is a type alias, for documentation see [`beef::generic::Cow`](./generic/struct.Cow.html).
6pub type Cow<'a, T> = crate::generic::Cow<'a, T, Wide>;
7
8pub(crate) mod internal {
9    #[derive(Clone, Copy, PartialEq, Eq)]
10    pub struct Wide;
11}
12use internal::Wide;
13
14impl Capacity for Wide {
15    type Field = Option<NonZeroUsize>;
16    type NonZero = NonZeroUsize;
17
18    #[inline]
19    fn len(fat: usize) -> usize {
20        fat
21    }
22
23    #[inline]
24    fn empty(len: usize) -> (usize, Self::Field) {
25        (len, None)
26    }
27
28    #[inline]
29    fn store(len: usize, capacity: usize) -> (usize, Self::Field) {
30        (len, NonZeroUsize::new(capacity))
31    }
32
33    #[inline]
34    fn unpack(fat: usize, capacity: NonZeroUsize) -> (usize, usize) {
35        (fat, capacity.get())
36    }
37
38    #[inline]
39    fn maybe(_: usize, capacity: Option<NonZeroUsize>) -> Option<NonZeroUsize> {
40        capacity
41    }
42}