/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::{ops, marker::PhantomData, u32}; usecrate::util::Recycler;
impl<T> Index<T> { /// Construct an Index from a raw u32. Caller is responsible for the /// value matching the underlying storage. pubfn from_u32(idx: u32) -> Self {
Index(idx, PhantomData)
}
}
// We explicitly implement Copy + Clone instead of using #[derive(Copy, Clone)] // because we don't want to require that T implements Clone + Copy. impl<T> Clone for Index<T> { fn clone(&self) -> Self { *self }
}
// We explicitly implement Copy + Clone instead of using #[derive(Copy, Clone)] // because we don't want to require that T implements Clone + Copy. impl<T> Clone for Range<T> { fn clone(&self) -> Self {
Range { start: self.start, end: self.end }
}
} impl<T> Copy for Range<T> {}
/// Check for an empty `Range` pubfn is_empty(self) -> bool { self.start.0 >= self.end.0
}
}
#[cfg_attr(feature = "capture", derive(Serialize))] pubstruct Storage<T> {
data: Vec<T>, /// Debug-only count of currently open ranges. Incremented by /// `open_range`, decremented by `close_range`. `clear`/`recycle` /// assert this is zero so a forgotten `close_range` is caught at /// frame reset rather than silently producing wrong ranges later. #[cfg(debug_assertions)]
open_count: u32,
}
pubfn recycle(&mutself, recycler: &mut Recycler) { #[cfg(debug_assertions)]
debug_assert_eq!( self.open_count, 0, "Storage::recycle with {} open range(s) — open_range without close_range", self.open_count,
);
recycler.recycle_vec(&mutself.data);
}
pubfn extend<II: IntoIterator<Item=T>>(&mutself, iter: II) -> Range<T> { let range = self.open_range(); self.data.extend(iter);
self.close_range(range)
}
/// Direct `&mut Vec<T>` access to the backing storage, for builders /// that push into multiple arenas in interleaved fashion and need to /// hold split borrows on the underlying `Vec`s simultaneously. /// Callers must only append; mutating or removing existing entries /// invalidates previously-issued `Index`/`Range` handles. Pair with /// `open_range`/`close_range` to capture the appended span. pubfn data_mut(&mutself) -> &mut Vec<T> {
&mutself.data
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.