ab_core_primitives/segments/
archival_history_segment.rs1use crate::pieces::{FlatPieces, Piece, PieceArray, PiecePosition};
2use crate::segments::RecordedHistorySegment;
3use derive_more::{Deref, DerefMut};
4use std::ops::{Index, IndexMut};
5
6#[derive(Debug, Clone, Eq, PartialEq, Deref, DerefMut)]
8#[repr(transparent)]
9pub struct ArchivedHistorySegment(FlatPieces);
10
11impl Default for ArchivedHistorySegment {
12 #[inline]
13 fn default() -> Self {
14 Self(FlatPieces::new(Self::NUM_PIECES))
15 }
16}
17
18impl Index<PiecePosition> for ArchivedHistorySegment {
19 type Output = PieceArray;
20
21 fn index(&self, index: PiecePosition) -> &Self::Output {
22 unsafe { self.get_unchecked(usize::from(index)) }
24 }
25}
26
27impl IndexMut<PiecePosition> for ArchivedHistorySegment {
28 fn index_mut(&mut self, index: PiecePosition) -> &mut Self::Output {
29 unsafe { self.get_unchecked_mut(usize::from(index)) }
31 }
32}
33
34impl ArchivedHistorySegment {
35 pub const NUM_PIECES: usize = RecordedHistorySegment::NUM_PIECES;
37 pub const SIZE: usize = Piece::SIZE * Self::NUM_PIECES;
43
44 pub fn to_shared(self) -> Self {
50 Self(self.0.to_shared())
51 }
52}