diff options
author | edef <edef@edef.eu> | 2024-02-15T22·20+0000 |
---|---|---|
committer | edef <edef@edef.eu> | 2024-02-27T11·50+0000 |
commit | e3860689babdf09a1e295e3640389467987b5611 (patch) | |
tree | 5936180456b49fa40d7367bdb278d05be6afe402 /tvix/tools/weave/src/bytes.rs | |
parent | 692f2bfb1c189f6de4cb733f9b1c68a2b2e56eef (diff) |
feat(tvix/tools/weave): init r/7617
Scalable tracing GC for the cache.nixos.org dataset. Change-Id: I6c7852796f28e1a1c7607384ffb55f44407e1185 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10765 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/tools/weave/src/bytes.rs')
-rw-r--r-- | tvix/tools/weave/src/bytes.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tvix/tools/weave/src/bytes.rs b/tvix/tools/weave/src/bytes.rs new file mode 100644 index 000000000000..c6dc2ebb4492 --- /dev/null +++ b/tvix/tools/weave/src/bytes.rs @@ -0,0 +1,27 @@ +use owning_ref::{OwningRef, StableAddress}; +use polars::export::arrow::buffer::Buffer; +use std::ops::Deref; + +/// An shared `[[u8; N]]` backed by a Polars [Buffer]. +pub type FixedBytes<const N: usize> = OwningRef<Bytes, [[u8; N]]>; + +/// Wrapper struct to make [Buffer] implement [StableAddress]. +/// TODO(edef): upstream the `impl` +pub struct Bytes(pub Buffer<u8>); + +/// SAFETY: [Buffer] is always an Arc+Vec indirection. +unsafe impl StableAddress for Bytes {} + +impl Bytes { + pub fn map<U: ?Sized>(self, f: impl FnOnce(&[u8]) -> &U) -> OwningRef<Self, U> { + OwningRef::new(self).map(f) + } +} + +impl Deref for Bytes { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + &*self.0 + } +} |