From 8464c49b0da6a96ee85a76c5eb304f349dda6719 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Wed, 19 Oct 2022 15:35:36 +1300 Subject: [PATCH 1/2] Update flatbuffers --- arrow/Cargo.toml | 2 +- arrow/src/ipc/gen/File.rs | 206 +- arrow/src/ipc/gen/Message.rs | 505 +++-- arrow/src/ipc/gen/Schema.rs | 1474 +++++++++------ arrow/src/ipc/gen/SparseTensor.rs | 2921 +++++++++++++---------------- arrow/src/ipc/gen/Tensor.rs | 246 ++- arrow/src/ipc/reader.rs | 93 +- 7 files changed, 2902 insertions(+), 2545 deletions(-) diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml index 134d274a839..88ed493965c 100644 --- a/arrow/Cargo.toml +++ b/arrow/Cargo.toml @@ -62,7 +62,7 @@ lz4 = { version = "1.23", default-features = false, optional = true } packed_simd = { version = "0.3", default-features = false, optional = true, package = "packed_simd_2" } chrono = { version = "0.4", default-features = false, features = ["clock"] } chrono-tz = { version = "0.6", default-features = false, optional = true } -flatbuffers = { version = "2.1.2", default-features = false, features = ["thiserror"], optional = true } +flatbuffers = { version = "22.9.2", default-features = false, features = ["thiserror"], optional = true } comfy-table = { version = "6.0", optional = true, default-features = false } pyo3 = { version = "0.17", default-features = false, optional = true } lexical-core = { version = "^0.8", default-features = false, features = ["write-integers", "write-floats", "parse-integers", "parse-floats"] } diff --git a/arrow/src/ipc/gen/File.rs b/arrow/src/ipc/gen/File.rs index 04cbc644137..9aafe910ba2 100644 --- a/arrow/src/ipc/gen/File.rs +++ b/arrow/src/ipc/gen/File.rs @@ -27,8 +27,13 @@ use std::{cmp::Ordering, mem}; #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Block(pub [u8; 24]); -impl std::fmt::Debug for Block { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl Default for Block { + fn default() -> Self { + Self([0; 24]) + } +} +impl core::fmt::Debug for Block { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("Block") .field("offset", &self.offset()) .field("metaDataLength", &self.metaDataLength()) @@ -38,39 +43,28 @@ impl std::fmt::Debug for Block { } impl flatbuffers::SimpleToVerifyInSlice for Block {} -impl flatbuffers::SafeSliceAccess for Block {} impl<'a> flatbuffers::Follow<'a> for Block { type Inner = &'a Block; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { <&'a Block>::follow(buf, loc) } } impl<'a> flatbuffers::Follow<'a> for &'a Block { type Inner = &'a Block; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { flatbuffers::follow_cast_ref::(buf, loc) } } impl<'b> flatbuffers::Push for Block { type Output = Block; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts(self as *const Block as *const u8, Self::size()) - }; - dst.copy_from_slice(src); - } -} -impl<'b> flatbuffers::Push for &'b Block { - type Output = Block; - - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Block as *const u8, Self::size()) - }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + let src = ::core::slice::from_raw_parts( + self as *const Block as *const u8, + Self::size(), + ); dst.copy_from_slice(src); } } @@ -85,7 +79,8 @@ impl<'a> flatbuffers::Verifiable for Block { v.in_buffer::(pos) } } -impl Block { + +impl<'a> Block { #[allow(clippy::too_many_arguments)] pub fn new(offset: i64, metaDataLength: i32, bodyLength: i64) -> Self { let mut s = Self([0; 24]); @@ -97,50 +92,60 @@ impl Block { /// Index to the start of the RecordBlock (note this is past the Message header) pub fn offset(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[0..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_offset(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } /// Length of the metadata pub fn metaDataLength(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[8..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_metaDataLength(&mut self, x: i32) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i32 as *const u8, + &x_le as *const _ as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -148,25 +153,30 @@ impl Block { /// Length of the data (this is aligned so there can be a gap between this and /// the metadata). pub fn bodyLength(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[16..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_bodyLength(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[16..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -185,16 +195,22 @@ pub struct Footer<'a> { impl<'a> flatbuffers::Follow<'a> for Footer<'a> { type Inner = Footer<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Footer<'a> { + pub const VT_VERSION: flatbuffers::VOffsetT = 4; + pub const VT_SCHEMA: flatbuffers::VOffsetT = 6; + pub const VT_DICTIONARIES: flatbuffers::VOffsetT = 8; + pub const VT_RECORDBATCHES: flatbuffers::VOffsetT = 10; + pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Footer { _tab: table } } #[allow(unused_mut)] @@ -219,49 +235,66 @@ impl<'a> Footer<'a> { builder.finish() } - pub const VT_VERSION: flatbuffers::VOffsetT = 4; - pub const VT_SCHEMA: flatbuffers::VOffsetT = 6; - pub const VT_DICTIONARIES: flatbuffers::VOffsetT = 8; - pub const VT_RECORDBATCHES: flatbuffers::VOffsetT = 10; - pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12; - #[inline] pub fn version(&self) -> MetadataVersion { - self._tab - .get::(Footer::VT_VERSION, Some(MetadataVersion::V1)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Footer::VT_VERSION, Some(MetadataVersion::V1)) + .unwrap() + } } #[inline] pub fn schema(&self) -> Option> { - self._tab - .get::>(Footer::VT_SCHEMA, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Footer::VT_SCHEMA, None) + } } #[inline] - pub fn dictionaries(&self) -> Option<&'a [Block]> { - self._tab - .get::>>( - Footer::VT_DICTIONARIES, - None, - ) - .map(|v| v.safe_slice()) + pub fn dictionaries(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Footer::VT_DICTIONARIES, + None, + ) + } } #[inline] - pub fn recordBatches(&self) -> Option<&'a [Block]> { - self._tab - .get::>>( - Footer::VT_RECORDBATCHES, - None, - ) - .map(|v| v.safe_slice()) + pub fn recordBatches(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Footer::VT_RECORDBATCHES, + None, + ) + } } /// User-defined metadata #[inline] pub fn custom_metadata( &self, ) -> Option>>> { - self._tab.get::>, - >>(Footer::VT_CUSTOM_METADATA, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Footer::VT_CUSTOM_METADATA, None) + } } } @@ -273,25 +306,25 @@ impl flatbuffers::Verifiable for Footer<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"version", Self::VT_VERSION, false)? + .visit_field::("version", Self::VT_VERSION, false)? .visit_field::>( - &"schema", + "schema", Self::VT_SCHEMA, false, )? .visit_field::>>( - &"dictionaries", + "dictionaries", Self::VT_DICTIONARIES, false, )? .visit_field::>>( - &"recordBatches", + "recordBatches", Self::VT_RECORDBATCHES, false, )? .visit_field::>, - >>(&"custom_metadata", Self::VT_CUSTOM_METADATA, false)? + >>("custom_metadata", Self::VT_CUSTOM_METADATA, false)? .finish(); Ok(()) } @@ -319,6 +352,7 @@ impl<'a> Default for FooterArgs<'a> { } } } + pub struct FooterBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -389,8 +423,8 @@ impl<'a: 'b, 'b> FooterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Footer<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Footer<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Footer"); ds.field("version", &self.version()); ds.field("schema", &self.schema()); @@ -400,18 +434,6 @@ impl std::fmt::Debug for Footer<'_> { ds.finish() } } -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_root_as_footer<'a>(buf: &'a [u8]) -> Footer<'a> { - unsafe { flatbuffers::root_unchecked::>(buf) } -} - -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_size_prefixed_root_as_footer<'a>(buf: &'a [u8]) -> Footer<'a> { - unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } -} - #[inline] /// Verifies that a buffer of bytes contains a `Footer` /// and returns it. diff --git a/arrow/src/ipc/gen/Message.rs b/arrow/src/ipc/gen/Message.rs index 707c62c0f76..d4b3a57f164 100644 --- a/arrow/src/ipc/gen/Message.rs +++ b/arrow/src/ipc/gen/Message.rs @@ -43,7 +43,7 @@ pub const ENUM_MAX_COMPRESSION_TYPE: i8 = 1; pub const ENUM_VALUES_COMPRESSION_TYPE: [CompressionType; 2] = [CompressionType::LZ4_FRAME, CompressionType::ZSTD]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct CompressionType(pub i8); #[allow(non_upper_case_globals)] @@ -63,8 +63,8 @@ impl CompressionType { } } } -impl std::fmt::Debug for CompressionType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for CompressionType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -75,8 +75,8 @@ impl std::fmt::Debug for CompressionType { impl<'a> flatbuffers::Follow<'a> for CompressionType { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -84,20 +84,21 @@ impl<'a> flatbuffers::Follow<'a> for CompressionType { impl flatbuffers::Push for CompressionType { type Output = CompressionType; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for CompressionType { + type Scalar = i8; #[inline] - fn to_little_endian(self) -> Self { - let b = i8::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i8 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i8::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); Self(b) } } @@ -135,7 +136,7 @@ pub const ENUM_VALUES_BODY_COMPRESSION_METHOD: [BodyCompressionMethod; 1] = /// Provided for forward compatibility in case we need to support different /// strategies for compressing the IPC message body (like whole-body /// compression rather than buffer-level) in the future -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct BodyCompressionMethod(pub i8); #[allow(non_upper_case_globals)] @@ -160,8 +161,8 @@ impl BodyCompressionMethod { } } } -impl std::fmt::Debug for BodyCompressionMethod { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for BodyCompressionMethod { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -172,8 +173,8 @@ impl std::fmt::Debug for BodyCompressionMethod { impl<'a> flatbuffers::Follow<'a> for BodyCompressionMethod { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -181,20 +182,21 @@ impl<'a> flatbuffers::Follow<'a> for BodyCompressionMethod { impl flatbuffers::Push for BodyCompressionMethod { type Output = BodyCompressionMethod; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for BodyCompressionMethod { + type Scalar = i8; #[inline] - fn to_little_endian(self) -> Self { - let b = i8::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i8 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i8::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); Self(b) } } @@ -243,7 +245,7 @@ pub const ENUM_VALUES_MESSAGE_HEADER: [MessageHeader; 6] = [ /// Arrow implementations do not need to implement all of the message types, /// which may include experimental metadata types. For maximum compatibility, /// it is best to send data using RecordBatch -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct MessageHeader(pub u8); #[allow(non_upper_case_globals)] @@ -278,8 +280,8 @@ impl MessageHeader { } } } -impl std::fmt::Debug for MessageHeader { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for MessageHeader { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -287,12 +289,11 @@ impl std::fmt::Debug for MessageHeader { } } } -pub struct MessageHeaderUnionTableOffset {} impl<'a> flatbuffers::Follow<'a> for MessageHeader { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -300,20 +301,21 @@ impl<'a> flatbuffers::Follow<'a> for MessageHeader { impl flatbuffers::Push for MessageHeader { type Output = MessageHeader; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for MessageHeader { + type Scalar = u8; #[inline] - fn to_little_endian(self) -> Self { - let b = u8::to_le(self.0); - Self(b) + fn to_little_endian(self) -> u8 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = u8::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); Self(b) } } @@ -330,6 +332,8 @@ impl<'a> flatbuffers::Verifiable for MessageHeader { } impl flatbuffers::SimpleToVerifyInSlice for MessageHeader {} +pub struct MessageHeaderUnionTableOffset {} + /// ---------------------------------------------------------------------- /// Data structures for describing a table row batch (a collection of /// equal-length Arrow arrays) @@ -343,8 +347,13 @@ impl flatbuffers::SimpleToVerifyInSlice for MessageHeader {} #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct FieldNode(pub [u8; 16]); -impl std::fmt::Debug for FieldNode { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl Default for FieldNode { + fn default() -> Self { + Self([0; 16]) + } +} +impl core::fmt::Debug for FieldNode { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("FieldNode") .field("length", &self.length()) .field("null_count", &self.null_count()) @@ -353,45 +362,28 @@ impl std::fmt::Debug for FieldNode { } impl flatbuffers::SimpleToVerifyInSlice for FieldNode {} -impl flatbuffers::SafeSliceAccess for FieldNode {} impl<'a> flatbuffers::Follow<'a> for FieldNode { type Inner = &'a FieldNode; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { <&'a FieldNode>::follow(buf, loc) } } impl<'a> flatbuffers::Follow<'a> for &'a FieldNode { type Inner = &'a FieldNode; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { flatbuffers::follow_cast_ref::(buf, loc) } } impl<'b> flatbuffers::Push for FieldNode { type Output = FieldNode; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts( - self as *const FieldNode as *const u8, - Self::size(), - ) - }; - dst.copy_from_slice(src); - } -} -impl<'b> flatbuffers::Push for &'b FieldNode { - type Output = FieldNode; - - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts( - *self as *const FieldNode as *const u8, - Self::size(), - ) - }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + let src = ::core::slice::from_raw_parts( + self as *const FieldNode as *const u8, + Self::size(), + ); dst.copy_from_slice(src); } } @@ -406,7 +398,8 @@ impl<'a> flatbuffers::Verifiable for FieldNode { v.in_buffer::(pos) } } -impl FieldNode { + +impl<'a> FieldNode { #[allow(clippy::too_many_arguments)] pub fn new(length: i64, null_count: i64) -> Self { let mut s = Self([0; 16]); @@ -418,25 +411,30 @@ impl FieldNode { /// The number of value slots in the Arrow array at this level of a nested /// tree pub fn length(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[0..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_length(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -445,25 +443,30 @@ impl FieldNode { /// to write their physical validity bitmap out as a materialized buffer, /// instead setting the length of the bitmap buffer to 0. pub fn null_count(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[8..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_null_count(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -482,16 +485,19 @@ pub struct BodyCompression<'a> { impl<'a> flatbuffers::Follow<'a> for BodyCompression<'a> { type Inner = BodyCompression<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> BodyCompression<'a> { + pub const VT_CODEC: flatbuffers::VOffsetT = 4; + pub const VT_METHOD: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { BodyCompression { _tab: table } } #[allow(unused_mut)] @@ -505,28 +511,36 @@ impl<'a> BodyCompression<'a> { builder.finish() } - pub const VT_CODEC: flatbuffers::VOffsetT = 4; - pub const VT_METHOD: flatbuffers::VOffsetT = 6; - - /// Compressor library + /// Compressor library. + /// For LZ4_FRAME, each compressed buffer must consist of a single frame. #[inline] pub fn codec(&self) -> CompressionType { - self._tab - .get::( - BodyCompression::VT_CODEC, - Some(CompressionType::LZ4_FRAME), - ) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + BodyCompression::VT_CODEC, + Some(CompressionType::LZ4_FRAME), + ) + .unwrap() + } } /// Indicates the way the record batch body was compressed #[inline] pub fn method(&self) -> BodyCompressionMethod { - self._tab - .get::( - BodyCompression::VT_METHOD, - Some(BodyCompressionMethod::BUFFER), - ) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + BodyCompression::VT_METHOD, + Some(BodyCompressionMethod::BUFFER), + ) + .unwrap() + } } } @@ -538,8 +552,8 @@ impl flatbuffers::Verifiable for BodyCompression<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"codec", Self::VT_CODEC, false)? - .visit_field::(&"method", Self::VT_METHOD, false)? + .visit_field::("codec", Self::VT_CODEC, false)? + .visit_field::("method", Self::VT_METHOD, false)? .finish(); Ok(()) } @@ -557,6 +571,7 @@ impl<'a> Default for BodyCompressionArgs { } } } + pub struct BodyCompressionBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -595,8 +610,8 @@ impl<'a: 'b, 'b> BodyCompressionBuilder<'a, 'b> { } } -impl std::fmt::Debug for BodyCompression<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for BodyCompression<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("BodyCompression"); ds.field("codec", &self.codec()); ds.field("method", &self.method()); @@ -616,16 +631,21 @@ pub struct RecordBatch<'a> { impl<'a> flatbuffers::Follow<'a> for RecordBatch<'a> { type Inner = RecordBatch<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> RecordBatch<'a> { + pub const VT_LENGTH: flatbuffers::VOffsetT = 4; + pub const VT_NODES: flatbuffers::VOffsetT = 6; + pub const VT_BUFFERS: flatbuffers::VOffsetT = 8; + pub const VT_COMPRESSION: flatbuffers::VOffsetT = 10; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { RecordBatch { _tab: table } } #[allow(unused_mut)] @@ -647,28 +667,32 @@ impl<'a> RecordBatch<'a> { builder.finish() } - pub const VT_LENGTH: flatbuffers::VOffsetT = 4; - pub const VT_NODES: flatbuffers::VOffsetT = 6; - pub const VT_BUFFERS: flatbuffers::VOffsetT = 8; - pub const VT_COMPRESSION: flatbuffers::VOffsetT = 10; - /// number of records / rows. The arrays in the batch should all have this /// length #[inline] pub fn length(&self) -> i64 { - self._tab - .get::(RecordBatch::VT_LENGTH, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(RecordBatch::VT_LENGTH, Some(0)) + .unwrap() + } } /// Nodes correspond to the pre-ordered flattened logical schema #[inline] - pub fn nodes(&self) -> Option<&'a [FieldNode]> { - self._tab - .get::>>( - RecordBatch::VT_NODES, - None, - ) - .map(|v| v.safe_slice()) + pub fn nodes(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + RecordBatch::VT_NODES, + None, + ) + } } /// Buffers correspond to the pre-ordered flattened buffer tree /// @@ -677,22 +701,31 @@ impl<'a> RecordBatch<'a> { /// bitmap and 1 for the values. For struct arrays, there will only be a /// single buffer for the validity (nulls) bitmap #[inline] - pub fn buffers(&self) -> Option<&'a [Buffer]> { - self._tab - .get::>>( - RecordBatch::VT_BUFFERS, - None, - ) - .map(|v| v.safe_slice()) + pub fn buffers(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + RecordBatch::VT_BUFFERS, + None, + ) + } } /// Optional compression of the message body #[inline] pub fn compression(&self) -> Option> { - self._tab - .get::>( - RecordBatch::VT_COMPRESSION, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + RecordBatch::VT_COMPRESSION, + None, + ) + } } } @@ -704,10 +737,10 @@ impl flatbuffers::Verifiable for RecordBatch<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"length", Self::VT_LENGTH, false)? - .visit_field::>>(&"nodes", Self::VT_NODES, false)? - .visit_field::>>(&"buffers", Self::VT_BUFFERS, false)? - .visit_field::>(&"compression", Self::VT_COMPRESSION, false)? + .visit_field::("length", Self::VT_LENGTH, false)? + .visit_field::>>("nodes", Self::VT_NODES, false)? + .visit_field::>>("buffers", Self::VT_BUFFERS, false)? + .visit_field::>("compression", Self::VT_COMPRESSION, false)? .finish(); Ok(()) } @@ -729,6 +762,7 @@ impl<'a> Default for RecordBatchArgs<'a> { } } } + pub struct RecordBatchBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -785,8 +819,8 @@ impl<'a: 'b, 'b> RecordBatchBuilder<'a, 'b> { } } -impl std::fmt::Debug for RecordBatch<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for RecordBatch<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("RecordBatch"); ds.field("length", &self.length()); ds.field("nodes", &self.nodes()); @@ -811,16 +845,20 @@ pub struct DictionaryBatch<'a> { impl<'a> flatbuffers::Follow<'a> for DictionaryBatch<'a> { type Inner = DictionaryBatch<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> DictionaryBatch<'a> { + pub const VT_ID: flatbuffers::VOffsetT = 4; + pub const VT_DATA: flatbuffers::VOffsetT = 6; + pub const VT_ISDELTA: flatbuffers::VOffsetT = 8; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { DictionaryBatch { _tab: table } } #[allow(unused_mut)] @@ -837,31 +875,42 @@ impl<'a> DictionaryBatch<'a> { builder.finish() } - pub const VT_ID: flatbuffers::VOffsetT = 4; - pub const VT_DATA: flatbuffers::VOffsetT = 6; - pub const VT_ISDELTA: flatbuffers::VOffsetT = 8; - #[inline] pub fn id(&self) -> i64 { - self._tab - .get::(DictionaryBatch::VT_ID, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(DictionaryBatch::VT_ID, Some(0)) + .unwrap() + } } #[inline] pub fn data(&self) -> Option> { - self._tab.get::>( - DictionaryBatch::VT_DATA, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>( + DictionaryBatch::VT_DATA, + None, + ) + } } /// If isDelta is true the values in the dictionary are to be appended to a /// dictionary with the indicated id. If isDelta is false this dictionary /// should replace the existing dictionary. #[inline] pub fn isDelta(&self) -> bool { - self._tab - .get::(DictionaryBatch::VT_ISDELTA, Some(false)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(DictionaryBatch::VT_ISDELTA, Some(false)) + .unwrap() + } } } @@ -873,13 +922,13 @@ impl flatbuffers::Verifiable for DictionaryBatch<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"id", Self::VT_ID, false)? + .visit_field::("id", Self::VT_ID, false)? .visit_field::>( - &"data", + "data", Self::VT_DATA, false, )? - .visit_field::(&"isDelta", Self::VT_ISDELTA, false)? + .visit_field::("isDelta", Self::VT_ISDELTA, false)? .finish(); Ok(()) } @@ -899,6 +948,7 @@ impl<'a> Default for DictionaryBatchArgs<'a> { } } } + pub struct DictionaryBatchBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -938,8 +988,8 @@ impl<'a: 'b, 'b> DictionaryBatchBuilder<'a, 'b> { } } -impl std::fmt::Debug for DictionaryBatch<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for DictionaryBatch<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("DictionaryBatch"); ds.field("id", &self.id()); ds.field("data", &self.data()); @@ -957,16 +1007,22 @@ pub struct Message<'a> { impl<'a> flatbuffers::Follow<'a> for Message<'a> { type Inner = Message<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Message<'a> { + pub const VT_VERSION: flatbuffers::VOffsetT = 4; + pub const VT_HEADER_TYPE: flatbuffers::VOffsetT = 6; + pub const VT_HEADER: flatbuffers::VOffsetT = 8; + pub const VT_BODYLENGTH: flatbuffers::VOffsetT = 10; + pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Message { _tab: table } } #[allow(unused_mut)] @@ -987,51 +1043,75 @@ impl<'a> Message<'a> { builder.finish() } - pub const VT_VERSION: flatbuffers::VOffsetT = 4; - pub const VT_HEADER_TYPE: flatbuffers::VOffsetT = 6; - pub const VT_HEADER: flatbuffers::VOffsetT = 8; - pub const VT_BODYLENGTH: flatbuffers::VOffsetT = 10; - pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 12; - #[inline] pub fn version(&self) -> MetadataVersion { - self._tab - .get::(Message::VT_VERSION, Some(MetadataVersion::V1)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Message::VT_VERSION, Some(MetadataVersion::V1)) + .unwrap() + } } #[inline] pub fn header_type(&self) -> MessageHeader { - self._tab - .get::(Message::VT_HEADER_TYPE, Some(MessageHeader::NONE)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Message::VT_HEADER_TYPE, Some(MessageHeader::NONE)) + .unwrap() + } } #[inline] pub fn header(&self) -> Option> { - self._tab - .get::>>( - Message::VT_HEADER, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Message::VT_HEADER, + None, + ) + } } #[inline] pub fn bodyLength(&self) -> i64 { - self._tab - .get::(Message::VT_BODYLENGTH, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Message::VT_BODYLENGTH, Some(0)) + .unwrap() + } } #[inline] pub fn custom_metadata( &self, ) -> Option>>> { - self._tab.get::>, - >>(Message::VT_CUSTOM_METADATA, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Message::VT_CUSTOM_METADATA, None) + } } #[inline] #[allow(non_snake_case)] pub fn header_as_schema(&self) -> Option> { if self.header_type() == MessageHeader::Schema { - self.header().map(Schema::init_from_table) + self.header().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Schema::init_from_table(t) } + }) } else { None } @@ -1041,7 +1121,12 @@ impl<'a> Message<'a> { #[allow(non_snake_case)] pub fn header_as_dictionary_batch(&self) -> Option> { if self.header_type() == MessageHeader::DictionaryBatch { - self.header().map(DictionaryBatch::init_from_table) + self.header().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { DictionaryBatch::init_from_table(t) } + }) } else { None } @@ -1051,7 +1136,12 @@ impl<'a> Message<'a> { #[allow(non_snake_case)] pub fn header_as_record_batch(&self) -> Option> { if self.header_type() == MessageHeader::RecordBatch { - self.header().map(RecordBatch::init_from_table) + self.header().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { RecordBatch::init_from_table(t) } + }) } else { None } @@ -1061,7 +1151,12 @@ impl<'a> Message<'a> { #[allow(non_snake_case)] pub fn header_as_tensor(&self) -> Option> { if self.header_type() == MessageHeader::Tensor { - self.header().map(Tensor::init_from_table) + self.header().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Tensor::init_from_table(t) } + }) } else { None } @@ -1071,7 +1166,12 @@ impl<'a> Message<'a> { #[allow(non_snake_case)] pub fn header_as_sparse_tensor(&self) -> Option> { if self.header_type() == MessageHeader::SparseTensor { - self.header().map(SparseTensor::init_from_table) + self.header().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { SparseTensor::init_from_table(t) } + }) } else { None } @@ -1086,8 +1186,8 @@ impl flatbuffers::Verifiable for Message<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"version", Self::VT_VERSION, false)? - .visit_union::(&"header_type", Self::VT_HEADER_TYPE, &"header", Self::VT_HEADER, false, |key, v, pos| { + .visit_field::("version", Self::VT_VERSION, false)? + .visit_union::("header_type", Self::VT_HEADER_TYPE, "header", Self::VT_HEADER, false, |key, v, pos| { match key { MessageHeader::Schema => v.verify_union_variant::>("MessageHeader::Schema", pos), MessageHeader::DictionaryBatch => v.verify_union_variant::>("MessageHeader::DictionaryBatch", pos), @@ -1097,8 +1197,8 @@ impl flatbuffers::Verifiable for Message<'_> { _ => Ok(()), } })? - .visit_field::(&"bodyLength", Self::VT_BODYLENGTH, false)? - .visit_field::>>>(&"custom_metadata", Self::VT_CUSTOM_METADATA, false)? + .visit_field::("bodyLength", Self::VT_BODYLENGTH, false)? + .visit_field::>>>("custom_metadata", Self::VT_CUSTOM_METADATA, false)? .finish(); Ok(()) } @@ -1126,6 +1226,7 @@ impl<'a> Default for MessageArgs<'a> { } } } + pub struct MessageBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1189,8 +1290,8 @@ impl<'a: 'b, 'b> MessageBuilder<'a, 'b> { } } -impl std::fmt::Debug for Message<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Message<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Message"); ds.field("version", &self.version()); ds.field("header_type", &self.header_type()); @@ -1255,18 +1356,6 @@ impl std::fmt::Debug for Message<'_> { ds.finish() } } -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_root_as_message<'a>(buf: &'a [u8]) -> Message<'a> { - unsafe { flatbuffers::root_unchecked::>(buf) } -} - -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_size_prefixed_root_as_message<'a>(buf: &'a [u8]) -> Message<'a> { - unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } -} - #[inline] /// Verifies that a buffer of bytes contains a `Message` /// and returns it. diff --git a/arrow/src/ipc/gen/Schema.rs b/arrow/src/ipc/gen/Schema.rs index dd204e0704d..6479bece721 100644 --- a/arrow/src/ipc/gen/Schema.rs +++ b/arrow/src/ipc/gen/Schema.rs @@ -45,7 +45,7 @@ pub const ENUM_VALUES_METADATA_VERSION: [MetadataVersion; 5] = [ MetadataVersion::V5, ]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct MetadataVersion(pub i16); #[allow(non_upper_case_globals)] @@ -83,8 +83,8 @@ impl MetadataVersion { } } } -impl std::fmt::Debug for MetadataVersion { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for MetadataVersion { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -95,8 +95,8 @@ impl std::fmt::Debug for MetadataVersion { impl<'a> flatbuffers::Follow<'a> for MetadataVersion { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -104,20 +104,21 @@ impl<'a> flatbuffers::Follow<'a> for MetadataVersion { impl flatbuffers::Push for MetadataVersion { type Output = MetadataVersion; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for MetadataVersion { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -172,7 +173,7 @@ pub const ENUM_VALUES_FEATURE: [Feature; 3] = [ /// Enums added to this list should be assigned power-of-two values /// to facilitate exchanging and comparing bitmaps for supported /// features. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Feature(pub i64); #[allow(non_upper_case_globals)] @@ -204,8 +205,8 @@ impl Feature { } } } -impl std::fmt::Debug for Feature { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for Feature { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -216,8 +217,8 @@ impl std::fmt::Debug for Feature { impl<'a> flatbuffers::Follow<'a> for Feature { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -225,20 +226,21 @@ impl<'a> flatbuffers::Follow<'a> for Feature { impl flatbuffers::Push for Feature { type Output = Feature; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for Feature { + type Scalar = i64; #[inline] - fn to_little_endian(self) -> Self { - let b = i64::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i64 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i64::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i64) -> Self { + let b = i64::from_le(v); Self(b) } } @@ -272,7 +274,7 @@ pub const ENUM_MAX_UNION_MODE: i16 = 1; #[allow(non_camel_case_types)] pub const ENUM_VALUES_UNION_MODE: [UnionMode; 2] = [UnionMode::Sparse, UnionMode::Dense]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct UnionMode(pub i16); #[allow(non_upper_case_globals)] @@ -292,8 +294,8 @@ impl UnionMode { } } } -impl std::fmt::Debug for UnionMode { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for UnionMode { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -304,8 +306,8 @@ impl std::fmt::Debug for UnionMode { impl<'a> flatbuffers::Follow<'a> for UnionMode { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -313,20 +315,21 @@ impl<'a> flatbuffers::Follow<'a> for UnionMode { impl flatbuffers::Push for UnionMode { type Output = UnionMode; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for UnionMode { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -361,7 +364,7 @@ pub const ENUM_MAX_PRECISION: i16 = 2; pub const ENUM_VALUES_PRECISION: [Precision; 3] = [Precision::HALF, Precision::SINGLE, Precision::DOUBLE]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Precision(pub i16); #[allow(non_upper_case_globals)] @@ -383,8 +386,8 @@ impl Precision { } } } -impl std::fmt::Debug for Precision { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for Precision { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -395,8 +398,8 @@ impl std::fmt::Debug for Precision { impl<'a> flatbuffers::Follow<'a> for Precision { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -404,20 +407,21 @@ impl<'a> flatbuffers::Follow<'a> for Precision { impl flatbuffers::Push for Precision { type Output = Precision; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for Precision { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -451,7 +455,7 @@ pub const ENUM_MAX_DATE_UNIT: i16 = 1; #[allow(non_camel_case_types)] pub const ENUM_VALUES_DATE_UNIT: [DateUnit; 2] = [DateUnit::DAY, DateUnit::MILLISECOND]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct DateUnit(pub i16); #[allow(non_upper_case_globals)] @@ -471,8 +475,8 @@ impl DateUnit { } } } -impl std::fmt::Debug for DateUnit { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for DateUnit { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -483,8 +487,8 @@ impl std::fmt::Debug for DateUnit { impl<'a> flatbuffers::Follow<'a> for DateUnit { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -492,20 +496,21 @@ impl<'a> flatbuffers::Follow<'a> for DateUnit { impl flatbuffers::Push for DateUnit { type Output = DateUnit; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for DateUnit { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -544,7 +549,7 @@ pub const ENUM_VALUES_TIME_UNIT: [TimeUnit; 4] = [ TimeUnit::NANOSECOND, ]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct TimeUnit(pub i16); #[allow(non_upper_case_globals)] @@ -573,8 +578,8 @@ impl TimeUnit { } } } -impl std::fmt::Debug for TimeUnit { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for TimeUnit { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -585,8 +590,8 @@ impl std::fmt::Debug for TimeUnit { impl<'a> flatbuffers::Follow<'a> for TimeUnit { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -594,20 +599,21 @@ impl<'a> flatbuffers::Follow<'a> for TimeUnit { impl flatbuffers::Push for TimeUnit { type Output = TimeUnit; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for TimeUnit { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -633,7 +639,7 @@ pub const ENUM_MIN_INTERVAL_UNIT: i16 = 0; since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021." )] -pub const ENUM_MAX_INTERVAL_UNIT: i16 = 1; +pub const ENUM_MAX_INTERVAL_UNIT: i16 = 2; #[deprecated( since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021." @@ -645,7 +651,7 @@ pub const ENUM_VALUES_INTERVAL_UNIT: [IntervalUnit; 3] = [ IntervalUnit::MONTH_DAY_NANO, ]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct IntervalUnit(pub i16); #[allow(non_upper_case_globals)] @@ -668,8 +674,8 @@ impl IntervalUnit { } } } -impl std::fmt::Debug for IntervalUnit { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for IntervalUnit { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -680,8 +686,8 @@ impl std::fmt::Debug for IntervalUnit { impl<'a> flatbuffers::Follow<'a> for IntervalUnit { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -689,20 +695,21 @@ impl<'a> flatbuffers::Follow<'a> for IntervalUnit { impl flatbuffers::Push for IntervalUnit { type Output = IntervalUnit; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for IntervalUnit { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -762,7 +769,7 @@ pub const ENUM_VALUES_TYPE: [Type; 22] = [ /// ---------------------------------------------------------------------- /// Top-level Type value, enabling extensible type-specific metadata. We can /// add new logical types to Type without breaking backwards compatibility -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Type(pub u8); #[allow(non_upper_case_globals)] @@ -845,8 +852,8 @@ impl Type { } } } -impl std::fmt::Debug for Type { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for Type { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -854,12 +861,11 @@ impl std::fmt::Debug for Type { } } } -pub struct TypeUnionTableOffset {} impl<'a> flatbuffers::Follow<'a> for Type { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -867,20 +873,21 @@ impl<'a> flatbuffers::Follow<'a> for Type { impl flatbuffers::Push for Type { type Output = Type; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for Type { + type Scalar = u8; #[inline] - fn to_little_endian(self) -> Self { - let b = u8::to_le(self.0); - Self(b) + fn to_little_endian(self) -> u8 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = u8::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); Self(b) } } @@ -897,6 +904,8 @@ impl<'a> flatbuffers::Verifiable for Type { } impl flatbuffers::SimpleToVerifyInSlice for Type {} +pub struct TypeUnionTableOffset {} + #[deprecated( since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021." @@ -919,7 +928,7 @@ pub const ENUM_VALUES_DICTIONARY_KIND: [DictionaryKind; 1] = [DictionaryKind::De /// Maintained for forwards compatibility, in the future /// Dictionaries might be explicit maps between integers and values /// allowing for non-contiguous index values -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct DictionaryKind(pub i16); #[allow(non_upper_case_globals)] @@ -937,8 +946,8 @@ impl DictionaryKind { } } } -impl std::fmt::Debug for DictionaryKind { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for DictionaryKind { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -949,8 +958,8 @@ impl std::fmt::Debug for DictionaryKind { impl<'a> flatbuffers::Follow<'a> for DictionaryKind { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -958,20 +967,21 @@ impl<'a> flatbuffers::Follow<'a> for DictionaryKind { impl flatbuffers::Push for DictionaryKind { type Output = DictionaryKind; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for DictionaryKind { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -1007,7 +1017,7 @@ pub const ENUM_VALUES_ENDIANNESS: [Endianness; 2] = [Endianness::Little, Endiann /// ---------------------------------------------------------------------- /// Endianness of the platform producing the data -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Endianness(pub i16); #[allow(non_upper_case_globals)] @@ -1027,8 +1037,8 @@ impl Endianness { } } } -impl std::fmt::Debug for Endianness { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for Endianness { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -1039,8 +1049,8 @@ impl std::fmt::Debug for Endianness { impl<'a> flatbuffers::Follow<'a> for Endianness { type Inner = Self; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); Self(b) } } @@ -1048,20 +1058,21 @@ impl<'a> flatbuffers::Follow<'a> for Endianness { impl flatbuffers::Push for Endianness { type Output = Endianness; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for Endianness { + type Scalar = i16; #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) + fn to_little_endian(self) -> i16 { + self.0.to_le() } #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); Self(b) } } @@ -1084,8 +1095,13 @@ impl flatbuffers::SimpleToVerifyInSlice for Endianness {} #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Buffer(pub [u8; 16]); -impl std::fmt::Debug for Buffer { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl Default for Buffer { + fn default() -> Self { + Self([0; 16]) + } +} +impl core::fmt::Debug for Buffer { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("Buffer") .field("offset", &self.offset()) .field("length", &self.length()) @@ -1094,42 +1110,28 @@ impl std::fmt::Debug for Buffer { } impl flatbuffers::SimpleToVerifyInSlice for Buffer {} -impl flatbuffers::SafeSliceAccess for Buffer {} impl<'a> flatbuffers::Follow<'a> for Buffer { type Inner = &'a Buffer; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { <&'a Buffer>::follow(buf, loc) } } impl<'a> flatbuffers::Follow<'a> for &'a Buffer { type Inner = &'a Buffer; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { flatbuffers::follow_cast_ref::(buf, loc) } } impl<'b> flatbuffers::Push for Buffer { type Output = Buffer; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts(self as *const Buffer as *const u8, Self::size()) - }; - dst.copy_from_slice(src); - } -} -impl<'b> flatbuffers::Push for &'b Buffer { - type Output = Buffer; - - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::std::slice::from_raw_parts( - *self as *const Buffer as *const u8, - Self::size(), - ) - }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + let src = ::core::slice::from_raw_parts( + self as *const Buffer as *const u8, + Self::size(), + ); dst.copy_from_slice(src); } } @@ -1144,7 +1146,8 @@ impl<'a> flatbuffers::Verifiable for Buffer { v.in_buffer::(pos) } } -impl Buffer { + +impl<'a> Buffer { #[allow(clippy::too_many_arguments)] pub fn new(offset: i64, length: i64) -> Self { let mut s = Self([0; 16]); @@ -1156,25 +1159,30 @@ impl Buffer { /// The relative offset into the shared memory page where the bytes for this /// buffer starts pub fn offset(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[0..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_offset(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -1185,25 +1193,30 @@ impl Buffer { /// after a buffer, but such padding bytes do not need to be accounted for in /// the size here. pub fn length(&self) -> i64 { - let mut mem = core::mem::MaybeUninit::::uninit(); - unsafe { + let mut mem = core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + EndianScalar::from_little_endian(unsafe { core::ptr::copy_nonoverlapping( self.0[8..].as_ptr(), mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); mem.assume_init() - } - .from_little_endian() + }) } pub fn set_length(&mut self, x: i64) { let x_le = x.to_little_endian(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot unsafe { core::ptr::copy_nonoverlapping( - &x_le as *const i64 as *const u8, + &x_le as *const _ as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + core::mem::size_of::<::Scalar>(), ); } } @@ -1220,16 +1233,16 @@ pub struct Null<'a> { impl<'a> flatbuffers::Follow<'a> for Null<'a> { type Inner = Null<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Null<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Null { _tab: table } } #[allow(unused_mut)] @@ -1260,6 +1273,7 @@ impl<'a> Default for NullArgs { NullArgs {} } } + pub struct NullBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1280,8 +1294,8 @@ impl<'a: 'b, 'b> NullBuilder<'a, 'b> { } } -impl std::fmt::Debug for Null<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Null<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Null"); ds.finish() } @@ -1299,16 +1313,16 @@ pub struct Struct_<'a> { impl<'a> flatbuffers::Follow<'a> for Struct_<'a> { type Inner = Struct_<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Struct_<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Struct_ { _tab: table } } #[allow(unused_mut)] @@ -1339,6 +1353,7 @@ impl<'a> Default for Struct_Args { Struct_Args {} } } + pub struct Struct_Builder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1361,8 +1376,8 @@ impl<'a: 'b, 'b> Struct_Builder<'a, 'b> { } } -impl std::fmt::Debug for Struct_<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Struct_<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Struct_"); ds.finish() } @@ -1377,16 +1392,16 @@ pub struct List<'a> { impl<'a> flatbuffers::Follow<'a> for List<'a> { type Inner = List<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> List<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { List { _tab: table } } #[allow(unused_mut)] @@ -1417,6 +1432,7 @@ impl<'a> Default for ListArgs { ListArgs {} } } + pub struct ListBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1437,8 +1453,8 @@ impl<'a: 'b, 'b> ListBuilder<'a, 'b> { } } -impl std::fmt::Debug for List<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for List<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("List"); ds.finish() } @@ -1455,16 +1471,16 @@ pub struct LargeList<'a> { impl<'a> flatbuffers::Follow<'a> for LargeList<'a> { type Inner = LargeList<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> LargeList<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { LargeList { _tab: table } } #[allow(unused_mut)] @@ -1495,6 +1511,7 @@ impl<'a> Default for LargeListArgs { LargeListArgs {} } } + pub struct LargeListBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1517,8 +1534,8 @@ impl<'a: 'b, 'b> LargeListBuilder<'a, 'b> { } } -impl std::fmt::Debug for LargeList<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for LargeList<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("LargeList"); ds.finish() } @@ -1533,16 +1550,18 @@ pub struct FixedSizeList<'a> { impl<'a> flatbuffers::Follow<'a> for FixedSizeList<'a> { type Inner = FixedSizeList<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> FixedSizeList<'a> { + pub const VT_LISTSIZE: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { FixedSizeList { _tab: table } } #[allow(unused_mut)] @@ -1555,14 +1574,17 @@ impl<'a> FixedSizeList<'a> { builder.finish() } - pub const VT_LISTSIZE: flatbuffers::VOffsetT = 4; - /// Number of list items per value #[inline] pub fn listSize(&self) -> i32 { - self._tab - .get::(FixedSizeList::VT_LISTSIZE, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(FixedSizeList::VT_LISTSIZE, Some(0)) + .unwrap() + } } } @@ -1574,7 +1596,7 @@ impl flatbuffers::Verifiable for FixedSizeList<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"listSize", Self::VT_LISTSIZE, false)? + .visit_field::("listSize", Self::VT_LISTSIZE, false)? .finish(); Ok(()) } @@ -1588,6 +1610,7 @@ impl<'a> Default for FixedSizeListArgs { FixedSizeListArgs { listSize: 0 } } } + pub struct FixedSizeListBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1615,8 +1638,8 @@ impl<'a: 'b, 'b> FixedSizeListBuilder<'a, 'b> { } } -impl std::fmt::Debug for FixedSizeList<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for FixedSizeList<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("FixedSizeList"); ds.field("listSize", &self.listSize()); ds.finish() @@ -1657,16 +1680,18 @@ pub struct Map<'a> { impl<'a> flatbuffers::Follow<'a> for Map<'a> { type Inner = Map<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Map<'a> { + pub const VT_KEYSSORTED: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Map { _tab: table } } #[allow(unused_mut)] @@ -1679,14 +1704,17 @@ impl<'a> Map<'a> { builder.finish() } - pub const VT_KEYSSORTED: flatbuffers::VOffsetT = 4; - /// Set to true if the keys within each value are sorted #[inline] pub fn keysSorted(&self) -> bool { - self._tab - .get::(Map::VT_KEYSSORTED, Some(false)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Map::VT_KEYSSORTED, Some(false)) + .unwrap() + } } } @@ -1698,7 +1726,7 @@ impl flatbuffers::Verifiable for Map<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"keysSorted", Self::VT_KEYSSORTED, false)? + .visit_field::("keysSorted", Self::VT_KEYSSORTED, false)? .finish(); Ok(()) } @@ -1712,6 +1740,7 @@ impl<'a> Default for MapArgs { MapArgs { keysSorted: false } } } + pub struct MapBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1737,8 +1766,8 @@ impl<'a: 'b, 'b> MapBuilder<'a, 'b> { } } -impl std::fmt::Debug for Map<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Map<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Map"); ds.field("keysSorted", &self.keysSorted()); ds.finish() @@ -1758,16 +1787,19 @@ pub struct Union<'a> { impl<'a> flatbuffers::Follow<'a> for Union<'a> { type Inner = Union<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Union<'a> { + pub const VT_MODE: flatbuffers::VOffsetT = 4; + pub const VT_TYPEIDS: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Union { _tab: table } } #[allow(unused_mut)] @@ -1783,22 +1815,29 @@ impl<'a> Union<'a> { builder.finish() } - pub const VT_MODE: flatbuffers::VOffsetT = 4; - pub const VT_TYPEIDS: flatbuffers::VOffsetT = 6; - #[inline] pub fn mode(&self) -> UnionMode { - self._tab - .get::(Union::VT_MODE, Some(UnionMode::Sparse)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Union::VT_MODE, Some(UnionMode::Sparse)) + .unwrap() + } } #[inline] pub fn typeIds(&self) -> Option> { - self._tab - .get::>>( - Union::VT_TYPEIDS, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Union::VT_TYPEIDS, + None, + ) + } } } @@ -1810,9 +1849,9 @@ impl flatbuffers::Verifiable for Union<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"mode", Self::VT_MODE, false)? + .visit_field::("mode", Self::VT_MODE, false)? .visit_field::>>( - &"typeIds", + "typeIds", Self::VT_TYPEIDS, false, )? @@ -1833,6 +1872,7 @@ impl<'a> Default for UnionArgs<'a> { } } } + pub struct UnionBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1866,8 +1906,8 @@ impl<'a: 'b, 'b> UnionBuilder<'a, 'b> { } } -impl std::fmt::Debug for Union<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Union<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Union"); ds.field("mode", &self.mode()); ds.field("typeIds", &self.typeIds()); @@ -1884,16 +1924,19 @@ pub struct Int<'a> { impl<'a> flatbuffers::Follow<'a> for Int<'a> { type Inner = Int<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Int<'a> { + pub const VT_BITWIDTH: flatbuffers::VOffsetT = 4; + pub const VT_IS_SIGNED: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Int { _tab: table } } #[allow(unused_mut)] @@ -1907,18 +1950,23 @@ impl<'a> Int<'a> { builder.finish() } - pub const VT_BITWIDTH: flatbuffers::VOffsetT = 4; - pub const VT_IS_SIGNED: flatbuffers::VOffsetT = 6; - #[inline] pub fn bitWidth(&self) -> i32 { - self._tab.get::(Int::VT_BITWIDTH, Some(0)).unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Int::VT_BITWIDTH, Some(0)).unwrap() } } #[inline] pub fn is_signed(&self) -> bool { - self._tab - .get::(Int::VT_IS_SIGNED, Some(false)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Int::VT_IS_SIGNED, Some(false)) + .unwrap() + } } } @@ -1930,8 +1978,8 @@ impl flatbuffers::Verifiable for Int<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"bitWidth", Self::VT_BITWIDTH, false)? - .visit_field::(&"is_signed", Self::VT_IS_SIGNED, false)? + .visit_field::("bitWidth", Self::VT_BITWIDTH, false)? + .visit_field::("is_signed", Self::VT_IS_SIGNED, false)? .finish(); Ok(()) } @@ -1949,6 +1997,7 @@ impl<'a> Default for IntArgs { } } } + pub struct IntBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -1978,8 +2027,8 @@ impl<'a: 'b, 'b> IntBuilder<'a, 'b> { } } -impl std::fmt::Debug for Int<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Int<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Int"); ds.field("bitWidth", &self.bitWidth()); ds.field("is_signed", &self.is_signed()); @@ -1996,16 +2045,18 @@ pub struct FloatingPoint<'a> { impl<'a> flatbuffers::Follow<'a> for FloatingPoint<'a> { type Inner = FloatingPoint<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> FloatingPoint<'a> { + pub const VT_PRECISION: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { FloatingPoint { _tab: table } } #[allow(unused_mut)] @@ -2018,13 +2069,16 @@ impl<'a> FloatingPoint<'a> { builder.finish() } - pub const VT_PRECISION: flatbuffers::VOffsetT = 4; - #[inline] pub fn precision(&self) -> Precision { - self._tab - .get::(FloatingPoint::VT_PRECISION, Some(Precision::HALF)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(FloatingPoint::VT_PRECISION, Some(Precision::HALF)) + .unwrap() + } } } @@ -2036,7 +2090,7 @@ impl flatbuffers::Verifiable for FloatingPoint<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"precision", Self::VT_PRECISION, false)? + .visit_field::("precision", Self::VT_PRECISION, false)? .finish(); Ok(()) } @@ -2052,6 +2106,7 @@ impl<'a> Default for FloatingPointArgs { } } } + pub struct FloatingPointBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2082,8 +2137,8 @@ impl<'a: 'b, 'b> FloatingPointBuilder<'a, 'b> { } } -impl std::fmt::Debug for FloatingPoint<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for FloatingPoint<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("FloatingPoint"); ds.field("precision", &self.precision()); ds.finish() @@ -2100,16 +2155,16 @@ pub struct Utf8<'a> { impl<'a> flatbuffers::Follow<'a> for Utf8<'a> { type Inner = Utf8<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Utf8<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Utf8 { _tab: table } } #[allow(unused_mut)] @@ -2140,6 +2195,7 @@ impl<'a> Default for Utf8Args { Utf8Args {} } } + pub struct Utf8Builder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2160,8 +2216,8 @@ impl<'a: 'b, 'b> Utf8Builder<'a, 'b> { } } -impl std::fmt::Debug for Utf8<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Utf8<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Utf8"); ds.finish() } @@ -2177,16 +2233,16 @@ pub struct Binary<'a> { impl<'a> flatbuffers::Follow<'a> for Binary<'a> { type Inner = Binary<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Binary<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Binary { _tab: table } } #[allow(unused_mut)] @@ -2217,6 +2273,7 @@ impl<'a> Default for BinaryArgs { BinaryArgs {} } } + pub struct BinaryBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2239,8 +2296,8 @@ impl<'a: 'b, 'b> BinaryBuilder<'a, 'b> { } } -impl std::fmt::Debug for Binary<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Binary<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Binary"); ds.finish() } @@ -2257,16 +2314,16 @@ pub struct LargeUtf8<'a> { impl<'a> flatbuffers::Follow<'a> for LargeUtf8<'a> { type Inner = LargeUtf8<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> LargeUtf8<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { LargeUtf8 { _tab: table } } #[allow(unused_mut)] @@ -2297,6 +2354,7 @@ impl<'a> Default for LargeUtf8Args { LargeUtf8Args {} } } + pub struct LargeUtf8Builder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2319,8 +2377,8 @@ impl<'a: 'b, 'b> LargeUtf8Builder<'a, 'b> { } } -impl std::fmt::Debug for LargeUtf8<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for LargeUtf8<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("LargeUtf8"); ds.finish() } @@ -2337,16 +2395,16 @@ pub struct LargeBinary<'a> { impl<'a> flatbuffers::Follow<'a> for LargeBinary<'a> { type Inner = LargeBinary<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> LargeBinary<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { LargeBinary { _tab: table } } #[allow(unused_mut)] @@ -2377,6 +2435,7 @@ impl<'a> Default for LargeBinaryArgs { LargeBinaryArgs {} } } + pub struct LargeBinaryBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2399,8 +2458,8 @@ impl<'a: 'b, 'b> LargeBinaryBuilder<'a, 'b> { } } -impl std::fmt::Debug for LargeBinary<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for LargeBinary<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("LargeBinary"); ds.finish() } @@ -2415,16 +2474,18 @@ pub struct FixedSizeBinary<'a> { impl<'a> flatbuffers::Follow<'a> for FixedSizeBinary<'a> { type Inner = FixedSizeBinary<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> FixedSizeBinary<'a> { + pub const VT_BYTEWIDTH: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { FixedSizeBinary { _tab: table } } #[allow(unused_mut)] @@ -2437,14 +2498,17 @@ impl<'a> FixedSizeBinary<'a> { builder.finish() } - pub const VT_BYTEWIDTH: flatbuffers::VOffsetT = 4; - /// Number of bytes per value #[inline] pub fn byteWidth(&self) -> i32 { - self._tab - .get::(FixedSizeBinary::VT_BYTEWIDTH, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(FixedSizeBinary::VT_BYTEWIDTH, Some(0)) + .unwrap() + } } } @@ -2456,7 +2520,7 @@ impl flatbuffers::Verifiable for FixedSizeBinary<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"byteWidth", Self::VT_BYTEWIDTH, false)? + .visit_field::("byteWidth", Self::VT_BYTEWIDTH, false)? .finish(); Ok(()) } @@ -2470,6 +2534,7 @@ impl<'a> Default for FixedSizeBinaryArgs { FixedSizeBinaryArgs { byteWidth: 0 } } } + pub struct FixedSizeBinaryBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2497,8 +2562,8 @@ impl<'a: 'b, 'b> FixedSizeBinaryBuilder<'a, 'b> { } } -impl std::fmt::Debug for FixedSizeBinary<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for FixedSizeBinary<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("FixedSizeBinary"); ds.field("byteWidth", &self.byteWidth()); ds.finish() @@ -2514,16 +2579,16 @@ pub struct Bool<'a> { impl<'a> flatbuffers::Follow<'a> for Bool<'a> { type Inner = Bool<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Bool<'a> { #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Bool { _tab: table } } #[allow(unused_mut)] @@ -2554,6 +2619,7 @@ impl<'a> Default for BoolArgs { BoolArgs {} } } + pub struct BoolBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2574,8 +2640,8 @@ impl<'a: 'b, 'b> BoolBuilder<'a, 'b> { } } -impl std::fmt::Debug for Bool<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Bool<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Bool"); ds.finish() } @@ -2594,16 +2660,20 @@ pub struct Decimal<'a> { impl<'a> flatbuffers::Follow<'a> for Decimal<'a> { type Inner = Decimal<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Decimal<'a> { + pub const VT_PRECISION: flatbuffers::VOffsetT = 4; + pub const VT_SCALE: flatbuffers::VOffsetT = 6; + pub const VT_BITWIDTH: flatbuffers::VOffsetT = 8; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Decimal { _tab: table } } #[allow(unused_mut)] @@ -2618,29 +2688,38 @@ impl<'a> Decimal<'a> { builder.finish() } - pub const VT_PRECISION: flatbuffers::VOffsetT = 4; - pub const VT_SCALE: flatbuffers::VOffsetT = 6; - pub const VT_BITWIDTH: flatbuffers::VOffsetT = 8; - /// Total number of decimal digits #[inline] pub fn precision(&self) -> i32 { - self._tab - .get::(Decimal::VT_PRECISION, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Decimal::VT_PRECISION, Some(0)) + .unwrap() + } } /// Number of digits after the decimal point "." #[inline] pub fn scale(&self) -> i32 { - self._tab.get::(Decimal::VT_SCALE, Some(0)).unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Decimal::VT_SCALE, Some(0)).unwrap() } } /// Number of bits per value. The only accepted widths are 128 and 256. /// We use bitWidth for consistency with Int::bitWidth. #[inline] pub fn bitWidth(&self) -> i32 { - self._tab - .get::(Decimal::VT_BITWIDTH, Some(128)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Decimal::VT_BITWIDTH, Some(128)) + .unwrap() + } } } @@ -2652,9 +2731,9 @@ impl flatbuffers::Verifiable for Decimal<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"precision", Self::VT_PRECISION, false)? - .visit_field::(&"scale", Self::VT_SCALE, false)? - .visit_field::(&"bitWidth", Self::VT_BITWIDTH, false)? + .visit_field::("precision", Self::VT_PRECISION, false)? + .visit_field::("scale", Self::VT_SCALE, false)? + .visit_field::("bitWidth", Self::VT_BITWIDTH, false)? .finish(); Ok(()) } @@ -2674,6 +2753,7 @@ impl<'a> Default for DecimalArgs { } } } + pub struct DecimalBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2710,8 +2790,8 @@ impl<'a: 'b, 'b> DecimalBuilder<'a, 'b> { } } -impl std::fmt::Debug for Decimal<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Decimal<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Decimal"); ds.field("precision", &self.precision()); ds.field("scale", &self.scale()); @@ -2722,8 +2802,8 @@ impl std::fmt::Debug for Decimal<'_> { pub enum DateOffset {} #[derive(Copy, Clone, PartialEq)] -/// Date is either a 32-bit or 64-bit type representing elapsed time since UNIX -/// epoch (1970-01-01), stored in either of two units: +/// Date is either a 32-bit or 64-bit signed integer type representing an +/// elapsed time since UNIX epoch (1970-01-01), stored in either of two units: /// /// * Milliseconds (64 bits) indicating UNIX time elapsed since the epoch (no /// leap seconds), where the values are evenly divisible by 86400000 @@ -2735,16 +2815,18 @@ pub struct Date<'a> { impl<'a> flatbuffers::Follow<'a> for Date<'a> { type Inner = Date<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Date<'a> { + pub const VT_UNIT: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Date { _tab: table } } #[allow(unused_mut)] @@ -2757,13 +2839,16 @@ impl<'a> Date<'a> { builder.finish() } - pub const VT_UNIT: flatbuffers::VOffsetT = 4; - #[inline] pub fn unit(&self) -> DateUnit { - self._tab - .get::(Date::VT_UNIT, Some(DateUnit::MILLISECOND)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Date::VT_UNIT, Some(DateUnit::MILLISECOND)) + .unwrap() + } } } @@ -2775,7 +2860,7 @@ impl flatbuffers::Verifiable for Date<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"unit", Self::VT_UNIT, false)? + .visit_field::("unit", Self::VT_UNIT, false)? .finish(); Ok(()) } @@ -2791,6 +2876,7 @@ impl<'a> Default for DateArgs { } } } + pub struct DateBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2816,8 +2902,8 @@ impl<'a: 'b, 'b> DateBuilder<'a, 'b> { } } -impl std::fmt::Debug for Date<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Date<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Date"); ds.field("unit", &self.unit()); ds.finish() @@ -2826,9 +2912,20 @@ impl std::fmt::Debug for Date<'_> { pub enum TimeOffset {} #[derive(Copy, Clone, PartialEq)] -/// Time type. The physical storage type depends on the unit -/// - SECOND and MILLISECOND: 32 bits -/// - MICROSECOND and NANOSECOND: 64 bits +/// Time is either a 32-bit or 64-bit signed integer type representing an +/// elapsed time since midnight, stored in either of four units: seconds, +/// milliseconds, microseconds or nanoseconds. +/// +/// The integer `bitWidth` depends on the `unit` and must be one of the following: +/// * SECOND and MILLISECOND: 32 bits +/// * MICROSECOND and NANOSECOND: 64 bits +/// +/// The allowed values are between 0 (inclusive) and 86400 (=24*60*60) seconds +/// (exclusive), adjusted for the time unit (for example, up to 86400000 +/// exclusive for the MILLISECOND unit). +/// This definition doesn't allow for leap seconds. Time values from +/// measurements with leap seconds will need to be corrected when ingesting +/// into Arrow (for example by replacing the value 86400 with 86399). pub struct Time<'a> { pub _tab: flatbuffers::Table<'a>, } @@ -2836,16 +2933,19 @@ pub struct Time<'a> { impl<'a> flatbuffers::Follow<'a> for Time<'a> { type Inner = Time<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Time<'a> { + pub const VT_UNIT: flatbuffers::VOffsetT = 4; + pub const VT_BITWIDTH: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Time { _tab: table } } #[allow(unused_mut)] @@ -2859,18 +2959,23 @@ impl<'a> Time<'a> { builder.finish() } - pub const VT_UNIT: flatbuffers::VOffsetT = 4; - pub const VT_BITWIDTH: flatbuffers::VOffsetT = 6; - #[inline] pub fn unit(&self) -> TimeUnit { - self._tab - .get::(Time::VT_UNIT, Some(TimeUnit::MILLISECOND)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Time::VT_UNIT, Some(TimeUnit::MILLISECOND)) + .unwrap() + } } #[inline] pub fn bitWidth(&self) -> i32 { - self._tab.get::(Time::VT_BITWIDTH, Some(32)).unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Time::VT_BITWIDTH, Some(32)).unwrap() } } } @@ -2882,8 +2987,8 @@ impl flatbuffers::Verifiable for Time<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"unit", Self::VT_UNIT, false)? - .visit_field::(&"bitWidth", Self::VT_BITWIDTH, false)? + .visit_field::("unit", Self::VT_UNIT, false)? + .visit_field::("bitWidth", Self::VT_BITWIDTH, false)? .finish(); Ok(()) } @@ -2901,6 +3006,7 @@ impl<'a> Default for TimeArgs { } } } + pub struct TimeBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -2930,8 +3036,8 @@ impl<'a: 'b, 'b> TimeBuilder<'a, 'b> { } } -impl std::fmt::Debug for Time<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Time<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Time"); ds.field("unit", &self.unit()); ds.field("bitWidth", &self.bitWidth()); @@ -2941,12 +3047,111 @@ impl std::fmt::Debug for Time<'_> { pub enum TimestampOffset {} #[derive(Copy, Clone, PartialEq)] -/// Time elapsed from the Unix epoch, 00:00:00.000 on 1 January 1970, excluding -/// leap seconds, as a 64-bit integer. Note that UNIX time does not include -/// leap seconds. +/// Timestamp is a 64-bit signed integer representing an elapsed time since a +/// fixed epoch, stored in either of four units: seconds, milliseconds, +/// microseconds or nanoseconds, and is optionally annotated with a timezone. +/// +/// Timestamp values do not include any leap seconds (in other words, all +/// days are considered 86400 seconds long). +/// +/// Timestamps with a non-empty timezone +/// ------------------------------------ +/// +/// If a Timestamp column has a non-empty timezone value, its epoch is +/// 1970-01-01 00:00:00 (January 1st 1970, midnight) in the *UTC* timezone +/// (the Unix epoch), regardless of the Timestamp's own timezone. +/// +/// Therefore, timestamp values with a non-empty timezone correspond to +/// physical points in time together with some additional information about +/// how the data was obtained and/or how to display it (the timezone). +/// +/// For example, the timestamp value 0 with the timezone string "Europe/Paris" +/// corresponds to "January 1st 1970, 00h00" in the UTC timezone, but the +/// application may prefer to display it as "January 1st 1970, 01h00" in +/// the Europe/Paris timezone (which is the same physical point in time). +/// +/// One consequence is that timestamp values with a non-empty timezone +/// can be compared and ordered directly, since they all share the same +/// well-known point of reference (the Unix epoch). +/// +/// Timestamps with an unset / empty timezone +/// ----------------------------------------- +/// +/// If a Timestamp column has no timezone value, its epoch is +/// 1970-01-01 00:00:00 (January 1st 1970, midnight) in an *unknown* timezone. +/// +/// Therefore, timestamp values without a timezone cannot be meaningfully +/// interpreted as physical points in time, but only as calendar / clock +/// indications ("wall clock time") in an unspecified timezone. +/// +/// For example, the timestamp value 0 with an empty timezone string +/// corresponds to "January 1st 1970, 00h00" in an unknown timezone: there +/// is not enough information to interpret it as a well-defined physical +/// point in time. +/// +/// One consequence is that timestamp values without a timezone cannot +/// be reliably compared or ordered, since they may have different points of +/// reference. In particular, it is *not* possible to interpret an unset +/// or empty timezone as the same as "UTC". +/// +/// Conversion between timezones +/// ---------------------------- /// -/// The Timestamp metadata supports both "time zone naive" and "time zone -/// aware" timestamps. Read about the timezone attribute for more detail +/// If a Timestamp column has a non-empty timezone, changing the timezone +/// to a different non-empty value is a metadata-only operation: +/// the timestamp values need not change as their point of reference remains +/// the same (the Unix epoch). +/// +/// However, if a Timestamp column has no timezone value, changing it to a +/// non-empty value requires to think about the desired semantics. +/// One possibility is to assume that the original timestamp values are +/// relative to the epoch of the timezone being set; timestamp values should +/// then adjusted to the Unix epoch (for example, changing the timezone from +/// empty to "Europe/Paris" would require converting the timestamp values +/// from "Europe/Paris" to "UTC", which seems counter-intuitive but is +/// nevertheless correct). +/// +/// Guidelines for encoding data from external libraries +/// ---------------------------------------------------- +/// +/// Date & time libraries often have multiple different data types for temporal +/// data. In order to ease interoperability between different implementations the +/// Arrow project has some recommendations for encoding these types into a Timestamp +/// column. +/// +/// An "instant" represents a physical point in time that has no relevant timezone +/// (for example, astronomical data). To encode an instant, use a Timestamp with +/// the timezone string set to "UTC", and make sure the Timestamp values +/// are relative to the UTC epoch (January 1st 1970, midnight). +/// +/// A "zoned date-time" represents a physical point in time annotated with an +/// informative timezone (for example, the timezone in which the data was +/// recorded). To encode a zoned date-time, use a Timestamp with the timezone +/// string set to the name of the timezone, and make sure the Timestamp values +/// are relative to the UTC epoch (January 1st 1970, midnight). +/// +/// (There is some ambiguity between an instant and a zoned date-time with the +/// UTC timezone. Both of these are stored the same in Arrow. Typically, +/// this distinction does not matter. If it does, then an application should +/// use custom metadata or an extension type to distinguish between the two cases.) +/// +/// An "offset date-time" represents a physical point in time combined with an +/// explicit offset from UTC. To encode an offset date-time, use a Timestamp +/// with the timezone string set to the numeric timezone offset string +/// (e.g. "+03:00"), and make sure the Timestamp values are relative to +/// the UTC epoch (January 1st 1970, midnight). +/// +/// A "naive date-time" (also called "local date-time" in some libraries) +/// represents a wall clock time combined with a calendar date, but with +/// no indication of how to map this information to a physical point in time. +/// Naive date-times must be handled with care because of this missing +/// information, and also because daylight saving time (DST) may make +/// some values ambiguous or non-existent. A naive date-time may be +/// stored as a struct with Date and Time fields. However, it may also be +/// encoded into a Timestamp column with an empty timezone. The timestamp +/// values should be computed "as if" the timezone of the date-time values +/// was UTC; for example, the naive date-time "January 1st 1970, 00h00" would +/// be encoded as timestamp value 0. pub struct Timestamp<'a> { pub _tab: flatbuffers::Table<'a>, } @@ -2954,16 +3159,19 @@ pub struct Timestamp<'a> { impl<'a> flatbuffers::Follow<'a> for Timestamp<'a> { type Inner = Timestamp<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Timestamp<'a> { + pub const VT_UNIT: flatbuffers::VOffsetT = 4; + pub const VT_TIMEZONE: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Timestamp { _tab: table } } #[allow(unused_mut)] @@ -2979,39 +3187,36 @@ impl<'a> Timestamp<'a> { builder.finish() } - pub const VT_UNIT: flatbuffers::VOffsetT = 4; - pub const VT_TIMEZONE: flatbuffers::VOffsetT = 6; - #[inline] pub fn unit(&self) -> TimeUnit { - self._tab - .get::(Timestamp::VT_UNIT, Some(TimeUnit::SECOND)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Timestamp::VT_UNIT, Some(TimeUnit::SECOND)) + .unwrap() + } } - /// The time zone is a string indicating the name of a time zone, one of: + /// The timezone is an optional string indicating the name of a timezone, + /// one of: /// - /// * As used in the Olson time zone database (the "tz database" or - /// "tzdata"), such as "America/New_York" - /// * An absolute time zone offset of the form +XX:XX or -XX:XX, such as +07:30 + /// * As used in the Olson timezone database (the "tz database" or + /// "tzdata"), such as "America/New_York". + /// * An absolute timezone offset of the form "+XX:XX" or "-XX:XX", + /// such as "+07:30". /// /// Whether a timezone string is present indicates different semantics about - /// the data: - /// - /// * If the time zone is null or equal to an empty string, the data is "time - /// zone naive" and shall be displayed *as is* to the user, not localized - /// to the locale of the user. This data can be though of as UTC but - /// without having "UTC" as the time zone, it is not considered to be - /// localized to any time zone - /// - /// * If the time zone is set to a valid value, values can be displayed as - /// "localized" to that time zone, even though the underlying 64-bit - /// integers are identical to the same data stored in UTC. Converting - /// between time zones is a metadata-only operation and does not change the - /// underlying values + /// the data (see above). #[inline] pub fn timezone(&self) -> Option<&'a str> { - self._tab - .get::>(Timestamp::VT_TIMEZONE, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Timestamp::VT_TIMEZONE, None) + } } } @@ -3023,9 +3228,9 @@ impl flatbuffers::Verifiable for Timestamp<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"unit", Self::VT_UNIT, false)? + .visit_field::("unit", Self::VT_UNIT, false)? .visit_field::>( - &"timezone", + "timezone", Self::VT_TIMEZONE, false, )? @@ -3046,6 +3251,7 @@ impl<'a> Default for TimestampArgs<'a> { } } } + pub struct TimestampBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -3080,8 +3286,8 @@ impl<'a: 'b, 'b> TimestampBuilder<'a, 'b> { } } -impl std::fmt::Debug for Timestamp<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Timestamp<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Timestamp"); ds.field("unit", &self.unit()); ds.field("timezone", &self.timezone()); @@ -3098,16 +3304,18 @@ pub struct Interval<'a> { impl<'a> flatbuffers::Follow<'a> for Interval<'a> { type Inner = Interval<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Interval<'a> { + pub const VT_UNIT: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Interval { _tab: table } } #[allow(unused_mut)] @@ -3120,13 +3328,16 @@ impl<'a> Interval<'a> { builder.finish() } - pub const VT_UNIT: flatbuffers::VOffsetT = 4; - #[inline] pub fn unit(&self) -> IntervalUnit { - self._tab - .get::(Interval::VT_UNIT, Some(IntervalUnit::YEAR_MONTH)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Interval::VT_UNIT, Some(IntervalUnit::YEAR_MONTH)) + .unwrap() + } } } @@ -3138,7 +3349,7 @@ impl flatbuffers::Verifiable for Interval<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"unit", Self::VT_UNIT, false)? + .visit_field::("unit", Self::VT_UNIT, false)? .finish(); Ok(()) } @@ -3154,6 +3365,7 @@ impl<'a> Default for IntervalArgs { } } } + pub struct IntervalBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -3184,8 +3396,8 @@ impl<'a: 'b, 'b> IntervalBuilder<'a, 'b> { } } -impl std::fmt::Debug for Interval<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Interval<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Interval"); ds.field("unit", &self.unit()); ds.finish() @@ -3201,16 +3413,18 @@ pub struct Duration<'a> { impl<'a> flatbuffers::Follow<'a> for Duration<'a> { type Inner = Duration<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Duration<'a> { + pub const VT_UNIT: flatbuffers::VOffsetT = 4; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Duration { _tab: table } } #[allow(unused_mut)] @@ -3223,13 +3437,16 @@ impl<'a> Duration<'a> { builder.finish() } - pub const VT_UNIT: flatbuffers::VOffsetT = 4; - #[inline] pub fn unit(&self) -> TimeUnit { - self._tab - .get::(Duration::VT_UNIT, Some(TimeUnit::MILLISECOND)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Duration::VT_UNIT, Some(TimeUnit::MILLISECOND)) + .unwrap() + } } } @@ -3241,7 +3458,7 @@ impl flatbuffers::Verifiable for Duration<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"unit", Self::VT_UNIT, false)? + .visit_field::("unit", Self::VT_UNIT, false)? .finish(); Ok(()) } @@ -3257,6 +3474,7 @@ impl<'a> Default for DurationArgs { } } } + pub struct DurationBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -3284,8 +3502,8 @@ impl<'a: 'b, 'b> DurationBuilder<'a, 'b> { } } -impl std::fmt::Debug for Duration<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Duration<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Duration"); ds.field("unit", &self.unit()); ds.finish() @@ -3304,16 +3522,19 @@ pub struct KeyValue<'a> { impl<'a> flatbuffers::Follow<'a> for KeyValue<'a> { type Inner = KeyValue<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> KeyValue<'a> { + pub const VT_KEY: flatbuffers::VOffsetT = 4; + pub const VT_VALUE: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { KeyValue { _tab: table } } #[allow(unused_mut)] @@ -3331,18 +3552,25 @@ impl<'a> KeyValue<'a> { builder.finish() } - pub const VT_KEY: flatbuffers::VOffsetT = 4; - pub const VT_VALUE: flatbuffers::VOffsetT = 6; - #[inline] pub fn key(&self) -> Option<&'a str> { - self._tab - .get::>(KeyValue::VT_KEY, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(KeyValue::VT_KEY, None) + } } #[inline] pub fn value(&self) -> Option<&'a str> { - self._tab - .get::>(KeyValue::VT_VALUE, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(KeyValue::VT_VALUE, None) + } } } @@ -3355,12 +3583,12 @@ impl flatbuffers::Verifiable for KeyValue<'_> { use flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>( - &"key", + "key", Self::VT_KEY, false, )? .visit_field::>( - &"value", + "value", Self::VT_VALUE, false, )? @@ -3381,6 +3609,7 @@ impl<'a> Default for KeyValueArgs<'a> { } } } + pub struct KeyValueBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -3413,8 +3642,8 @@ impl<'a: 'b, 'b> KeyValueBuilder<'a, 'b> { } } -impl std::fmt::Debug for KeyValue<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for KeyValue<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("KeyValue"); ds.field("key", &self.key()); ds.field("value", &self.value()); @@ -3431,16 +3660,21 @@ pub struct DictionaryEncoding<'a> { impl<'a> flatbuffers::Follow<'a> for DictionaryEncoding<'a> { type Inner = DictionaryEncoding<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> DictionaryEncoding<'a> { + pub const VT_ID: flatbuffers::VOffsetT = 4; + pub const VT_INDEXTYPE: flatbuffers::VOffsetT = 6; + pub const VT_ISORDERED: flatbuffers::VOffsetT = 8; + pub const VT_DICTIONARYKIND: flatbuffers::VOffsetT = 10; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { DictionaryEncoding { _tab: table } } #[allow(unused_mut)] @@ -3458,19 +3692,19 @@ impl<'a> DictionaryEncoding<'a> { builder.finish() } - pub const VT_ID: flatbuffers::VOffsetT = 4; - pub const VT_INDEXTYPE: flatbuffers::VOffsetT = 6; - pub const VT_ISORDERED: flatbuffers::VOffsetT = 8; - pub const VT_DICTIONARYKIND: flatbuffers::VOffsetT = 10; - /// The known dictionary id in the application where this data is used. In /// the file or streaming formats, the dictionary ids are found in the /// DictionaryBatch messages #[inline] pub fn id(&self) -> i64 { - self._tab - .get::(DictionaryEncoding::VT_ID, Some(0)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(DictionaryEncoding::VT_ID, Some(0)) + .unwrap() + } } /// The dictionary indices are constrained to be non-negative integers. If /// this field is null, the indices must be signed int32. To maximize @@ -3479,10 +3713,15 @@ impl<'a> DictionaryEncoding<'a> { /// and to avoid uint64 indices unless they are required by an application. #[inline] pub fn indexType(&self) -> Option> { - self._tab.get::>( - DictionaryEncoding::VT_INDEXTYPE, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>( + DictionaryEncoding::VT_INDEXTYPE, + None, + ) + } } /// By default, dictionaries are not ordered, or the order does not have /// semantic meaning. In some statistical, applications, dictionary-encoding @@ -3490,18 +3729,28 @@ impl<'a> DictionaryEncoding<'a> { /// preserve that metadata here #[inline] pub fn isOrdered(&self) -> bool { - self._tab - .get::(DictionaryEncoding::VT_ISORDERED, Some(false)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(DictionaryEncoding::VT_ISORDERED, Some(false)) + .unwrap() + } } #[inline] pub fn dictionaryKind(&self) -> DictionaryKind { - self._tab - .get::( - DictionaryEncoding::VT_DICTIONARYKIND, - Some(DictionaryKind::DenseArray), - ) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + DictionaryEncoding::VT_DICTIONARYKIND, + Some(DictionaryKind::DenseArray), + ) + .unwrap() + } } } @@ -3513,15 +3762,15 @@ impl flatbuffers::Verifiable for DictionaryEncoding<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"id", Self::VT_ID, false)? + .visit_field::("id", Self::VT_ID, false)? .visit_field::>( - &"indexType", + "indexType", Self::VT_INDEXTYPE, false, )? - .visit_field::(&"isOrdered", Self::VT_ISORDERED, false)? + .visit_field::("isOrdered", Self::VT_ISORDERED, false)? .visit_field::( - &"dictionaryKind", + "dictionaryKind", Self::VT_DICTIONARYKIND, false, )? @@ -3546,6 +3795,7 @@ impl<'a> Default for DictionaryEncodingArgs<'a> { } } } + pub struct DictionaryEncodingBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -3592,8 +3842,8 @@ impl<'a: 'b, 'b> DictionaryEncodingBuilder<'a, 'b> { } } -impl std::fmt::Debug for DictionaryEncoding<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for DictionaryEncoding<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("DictionaryEncoding"); ds.field("id", &self.id()); ds.field("indexType", &self.indexType()); @@ -3615,16 +3865,24 @@ pub struct Field<'a> { impl<'a> flatbuffers::Follow<'a> for Field<'a> { type Inner = Field<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Field<'a> { + pub const VT_NAME: flatbuffers::VOffsetT = 4; + pub const VT_NULLABLE: flatbuffers::VOffsetT = 6; + pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 8; + pub const VT_TYPE_: flatbuffers::VOffsetT = 10; + pub const VT_DICTIONARY: flatbuffers::VOffsetT = 12; + pub const VT_CHILDREN: flatbuffers::VOffsetT = 14; + pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 16; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Field { _tab: table } } #[allow(unused_mut)] @@ -3653,50 +3911,67 @@ impl<'a> Field<'a> { builder.finish() } - pub const VT_NAME: flatbuffers::VOffsetT = 4; - pub const VT_NULLABLE: flatbuffers::VOffsetT = 6; - pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 8; - pub const VT_TYPE_: flatbuffers::VOffsetT = 10; - pub const VT_DICTIONARY: flatbuffers::VOffsetT = 12; - pub const VT_CHILDREN: flatbuffers::VOffsetT = 14; - pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 16; - /// Name is not required, in i.e. a List #[inline] pub fn name(&self) -> Option<&'a str> { - self._tab - .get::>(Field::VT_NAME, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Field::VT_NAME, None) + } } /// Whether or not this field can contain nulls. Should be true in general. #[inline] pub fn nullable(&self) -> bool { - self._tab - .get::(Field::VT_NULLABLE, Some(false)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Field::VT_NULLABLE, Some(false)) + .unwrap() + } } #[inline] pub fn type_type(&self) -> Type { - self._tab - .get::(Field::VT_TYPE_TYPE, Some(Type::NONE)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Field::VT_TYPE_TYPE, Some(Type::NONE)) + .unwrap() + } } /// This is the type of the decoded value if the field is dictionary encoded. #[inline] pub fn type_(&self) -> Option> { - self._tab - .get::>>( - Field::VT_TYPE_, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Field::VT_TYPE_, + None, + ) + } } /// Present only if the field is dictionary encoded. #[inline] pub fn dictionary(&self) -> Option> { - self._tab - .get::>( - Field::VT_DICTIONARY, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + Field::VT_DICTIONARY, + None, + ) + } } /// children apply only to nested data types like Struct, List and Union. For /// primitive types children will have length 0. @@ -3704,24 +3979,39 @@ impl<'a> Field<'a> { pub fn children( &self, ) -> Option>>> { - self._tab.get::>, - >>(Field::VT_CHILDREN, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Field::VT_CHILDREN, None) + } } /// User-defined metadata #[inline] pub fn custom_metadata( &self, ) -> Option>>> { - self._tab.get::>, - >>(Field::VT_CUSTOM_METADATA, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Field::VT_CUSTOM_METADATA, None) + } } #[inline] #[allow(non_snake_case)] pub fn type_as_null(&self) -> Option> { if self.type_type() == Type::Null { - self.type_().map(Null::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Null::init_from_table(t) } + }) } else { None } @@ -3731,7 +4021,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_int(&self) -> Option> { if self.type_type() == Type::Int { - self.type_().map(Int::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Int::init_from_table(t) } + }) } else { None } @@ -3741,7 +4036,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_floating_point(&self) -> Option> { if self.type_type() == Type::FloatingPoint { - self.type_().map(FloatingPoint::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { FloatingPoint::init_from_table(t) } + }) } else { None } @@ -3751,7 +4051,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_binary(&self) -> Option> { if self.type_type() == Type::Binary { - self.type_().map(Binary::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Binary::init_from_table(t) } + }) } else { None } @@ -3761,7 +4066,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_utf_8(&self) -> Option> { if self.type_type() == Type::Utf8 { - self.type_().map(Utf8::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Utf8::init_from_table(t) } + }) } else { None } @@ -3771,7 +4081,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_bool(&self) -> Option> { if self.type_type() == Type::Bool { - self.type_().map(Bool::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Bool::init_from_table(t) } + }) } else { None } @@ -3781,7 +4096,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_decimal(&self) -> Option> { if self.type_type() == Type::Decimal { - self.type_().map(Decimal::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Decimal::init_from_table(t) } + }) } else { None } @@ -3791,7 +4111,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_date(&self) -> Option> { if self.type_type() == Type::Date { - self.type_().map(Date::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Date::init_from_table(t) } + }) } else { None } @@ -3801,7 +4126,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_time(&self) -> Option> { if self.type_type() == Type::Time { - self.type_().map(Time::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Time::init_from_table(t) } + }) } else { None } @@ -3811,7 +4141,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_timestamp(&self) -> Option> { if self.type_type() == Type::Timestamp { - self.type_().map(Timestamp::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Timestamp::init_from_table(t) } + }) } else { None } @@ -3821,7 +4156,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_interval(&self) -> Option> { if self.type_type() == Type::Interval { - self.type_().map(Interval::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Interval::init_from_table(t) } + }) } else { None } @@ -3831,7 +4171,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_list(&self) -> Option> { if self.type_type() == Type::List { - self.type_().map(List::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { List::init_from_table(t) } + }) } else { None } @@ -3841,7 +4186,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_struct_(&self) -> Option> { if self.type_type() == Type::Struct_ { - self.type_().map(Struct_::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Struct_::init_from_table(t) } + }) } else { None } @@ -3851,7 +4201,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_union(&self) -> Option> { if self.type_type() == Type::Union { - self.type_().map(Union::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Union::init_from_table(t) } + }) } else { None } @@ -3861,7 +4216,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_fixed_size_binary(&self) -> Option> { if self.type_type() == Type::FixedSizeBinary { - self.type_().map(FixedSizeBinary::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { FixedSizeBinary::init_from_table(t) } + }) } else { None } @@ -3871,7 +4231,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_fixed_size_list(&self) -> Option> { if self.type_type() == Type::FixedSizeList { - self.type_().map(FixedSizeList::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { FixedSizeList::init_from_table(t) } + }) } else { None } @@ -3881,7 +4246,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_map(&self) -> Option> { if self.type_type() == Type::Map { - self.type_().map(Map::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Map::init_from_table(t) } + }) } else { None } @@ -3891,7 +4261,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_duration(&self) -> Option> { if self.type_type() == Type::Duration { - self.type_().map(Duration::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Duration::init_from_table(t) } + }) } else { None } @@ -3901,7 +4276,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_large_binary(&self) -> Option> { if self.type_type() == Type::LargeBinary { - self.type_().map(LargeBinary::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { LargeBinary::init_from_table(t) } + }) } else { None } @@ -3911,7 +4291,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_large_utf_8(&self) -> Option> { if self.type_type() == Type::LargeUtf8 { - self.type_().map(LargeUtf8::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { LargeUtf8::init_from_table(t) } + }) } else { None } @@ -3921,7 +4306,12 @@ impl<'a> Field<'a> { #[allow(non_snake_case)] pub fn type_as_large_list(&self) -> Option> { if self.type_type() == Type::LargeList { - self.type_().map(LargeList::init_from_table) + self.type_().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { LargeList::init_from_table(t) } + }) } else { None } @@ -3936,9 +4326,9 @@ impl flatbuffers::Verifiable for Field<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::>(&"name", Self::VT_NAME, false)? - .visit_field::(&"nullable", Self::VT_NULLABLE, false)? - .visit_union::(&"type_type", Self::VT_TYPE_TYPE, &"type_", Self::VT_TYPE_, false, |key, v, pos| { + .visit_field::>("name", Self::VT_NAME, false)? + .visit_field::("nullable", Self::VT_NULLABLE, false)? + .visit_union::("type_type", Self::VT_TYPE_TYPE, "type_", Self::VT_TYPE_, false, |key, v, pos| { match key { Type::Null => v.verify_union_variant::>("Type::Null", pos), Type::Int => v.verify_union_variant::>("Type::Int", pos), @@ -3964,9 +4354,9 @@ impl flatbuffers::Verifiable for Field<'_> { _ => Ok(()), } })? - .visit_field::>(&"dictionary", Self::VT_DICTIONARY, false)? - .visit_field::>>>(&"children", Self::VT_CHILDREN, false)? - .visit_field::>>>(&"custom_metadata", Self::VT_CUSTOM_METADATA, false)? + .visit_field::>("dictionary", Self::VT_DICTIONARY, false)? + .visit_field::>>>("children", Self::VT_CHILDREN, false)? + .visit_field::>>>("custom_metadata", Self::VT_CUSTOM_METADATA, false)? .finish(); Ok(()) } @@ -4002,6 +4392,7 @@ impl<'a> Default for FieldArgs<'a> { } } } + pub struct FieldBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -4078,8 +4469,8 @@ impl<'a: 'b, 'b> FieldBuilder<'a, 'b> { } } -impl std::fmt::Debug for Field<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Field<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Field"); ds.field("name", &self.name()); ds.field("nullable", &self.nullable()); @@ -4318,16 +4709,21 @@ pub struct Schema<'a> { impl<'a> flatbuffers::Follow<'a> for Schema<'a> { type Inner = Schema<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Schema<'a> { + pub const VT_ENDIANNESS: flatbuffers::VOffsetT = 4; + pub const VT_FIELDS: flatbuffers::VOffsetT = 6; + pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 8; + pub const VT_FEATURES: flatbuffers::VOffsetT = 10; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Schema { _tab: table } } #[allow(unused_mut)] @@ -4349,44 +4745,59 @@ impl<'a> Schema<'a> { builder.finish() } - pub const VT_ENDIANNESS: flatbuffers::VOffsetT = 4; - pub const VT_FIELDS: flatbuffers::VOffsetT = 6; - pub const VT_CUSTOM_METADATA: flatbuffers::VOffsetT = 8; - pub const VT_FEATURES: flatbuffers::VOffsetT = 10; - /// endianness of the buffer /// it is Little Endian by default /// if endianness doesn't match the underlying system then the vectors need to be converted #[inline] pub fn endianness(&self) -> Endianness { - self._tab - .get::(Schema::VT_ENDIANNESS, Some(Endianness::Little)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Schema::VT_ENDIANNESS, Some(Endianness::Little)) + .unwrap() + } } #[inline] pub fn fields( &self, ) -> Option>>> { - self._tab.get::>, - >>(Schema::VT_FIELDS, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Schema::VT_FIELDS, None) + } } #[inline] pub fn custom_metadata( &self, ) -> Option>>> { - self._tab.get::>, - >>(Schema::VT_CUSTOM_METADATA, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Schema::VT_CUSTOM_METADATA, None) + } } /// Features used in the stream/file. #[inline] pub fn features(&self) -> Option> { - self._tab - .get::>>( - Schema::VT_FEATURES, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Schema::VT_FEATURES, + None, + ) + } } } @@ -4398,10 +4809,10 @@ impl flatbuffers::Verifiable for Schema<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"endianness", Self::VT_ENDIANNESS, false)? - .visit_field::>>>(&"fields", Self::VT_FIELDS, false)? - .visit_field::>>>(&"custom_metadata", Self::VT_CUSTOM_METADATA, false)? - .visit_field::>>(&"features", Self::VT_FEATURES, false)? + .visit_field::("endianness", Self::VT_ENDIANNESS, false)? + .visit_field::>>>("fields", Self::VT_FIELDS, false)? + .visit_field::>>>("custom_metadata", Self::VT_CUSTOM_METADATA, false)? + .visit_field::>>("features", Self::VT_FEATURES, false)? .finish(); Ok(()) } @@ -4431,6 +4842,7 @@ impl<'a> Default for SchemaArgs<'a> { } } } + pub struct SchemaBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -4491,8 +4903,8 @@ impl<'a: 'b, 'b> SchemaBuilder<'a, 'b> { } } -impl std::fmt::Debug for Schema<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Schema<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Schema"); ds.field("endianness", &self.endianness()); ds.field("fields", &self.fields()); @@ -4501,18 +4913,6 @@ impl std::fmt::Debug for Schema<'_> { ds.finish() } } -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_root_as_schema<'a>(buf: &'a [u8]) -> Schema<'a> { - unsafe { flatbuffers::root_unchecked::>(buf) } -} - -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_size_prefixed_root_as_schema<'a>(buf: &'a [u8]) -> Schema<'a> { - unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } -} - #[inline] /// Verifies that a buffer of bytes contains a `Schema` /// and returns it. diff --git a/arrow/src/ipc/gen/SparseTensor.rs b/arrow/src/ipc/gen/SparseTensor.rs index 986d21cda84..55d769bf3b1 100644 --- a/arrow/src/ipc/gen/SparseTensor.rs +++ b/arrow/src/ipc/gen/SparseTensor.rs @@ -24,200 +24,186 @@ use flatbuffers::EndianScalar; use std::{cmp::Ordering, mem}; // automatically generated by the FlatBuffers compiler, do not modify -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 0; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 1; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_SPARSE_MATRIX_COMPRESSED_AXIS: [SparseMatrixCompressedAxis; 2] = [ - SparseMatrixCompressedAxis::Row, - SparseMatrixCompressedAxis::Column, + SparseMatrixCompressedAxis::Row, + SparseMatrixCompressedAxis::Column, ]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct SparseMatrixCompressedAxis(pub i16); #[allow(non_upper_case_globals)] impl SparseMatrixCompressedAxis { - pub const Row: Self = Self(0); - pub const Column: Self = Self(1); - - pub const ENUM_MIN: i16 = 0; - pub const ENUM_MAX: i16 = 1; - pub const ENUM_VALUES: &'static [Self] = &[Self::Row, Self::Column]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::Row => Some("Row"), - Self::Column => Some("Column"), - _ => None, - } - } + pub const Row: Self = Self(0); + pub const Column: Self = Self(1); + + pub const ENUM_MIN: i16 = 0; + pub const ENUM_MAX: i16 = 1; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::Row, + Self::Column, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Row => Some("Row"), + Self::Column => Some("Column"), + _ => None, + } + } } -impl std::fmt::Debug for SparseMatrixCompressedAxis { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } +impl core::fmt::Debug for SparseMatrixCompressedAxis { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } } impl<'a> flatbuffers::Follow<'a> for SparseMatrixCompressedAxis { - type Inner = Self; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for SparseMatrixCompressedAxis { type Output = SparseMatrixCompressedAxis; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for SparseMatrixCompressedAxis { - #[inline] - fn to_little_endian(self) -> Self { - let b = i16::to_le(self.0); - Self(b) - } - #[inline] - fn from_little_endian(self) -> Self { - let b = i16::from_le(self.0); - Self(b) - } + type Scalar = i16; + #[inline] + fn to_little_endian(self) -> i16 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for SparseMatrixCompressedAxis { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - i16::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + i16::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for SparseMatrixCompressedAxis {} -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_SPARSE_TENSOR_INDEX: u8 = 0; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_SPARSE_TENSOR_INDEX: u8 = 3; -#[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." -)] +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_SPARSE_TENSOR_INDEX: [SparseTensorIndex; 4] = [ - SparseTensorIndex::NONE, - SparseTensorIndex::SparseTensorIndexCOO, - SparseTensorIndex::SparseMatrixIndexCSX, - SparseTensorIndex::SparseTensorIndexCSF, + SparseTensorIndex::NONE, + SparseTensorIndex::SparseTensorIndexCOO, + SparseTensorIndex::SparseMatrixIndexCSX, + SparseTensorIndex::SparseTensorIndexCSF, ]; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct SparseTensorIndex(pub u8); #[allow(non_upper_case_globals)] impl SparseTensorIndex { - pub const NONE: Self = Self(0); - pub const SparseTensorIndexCOO: Self = Self(1); - pub const SparseMatrixIndexCSX: Self = Self(2); - pub const SparseTensorIndexCSF: Self = Self(3); - - pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::NONE, - Self::SparseTensorIndexCOO, - Self::SparseMatrixIndexCSX, - Self::SparseTensorIndexCSF, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::NONE => Some("NONE"), - Self::SparseTensorIndexCOO => Some("SparseTensorIndexCOO"), - Self::SparseMatrixIndexCSX => Some("SparseMatrixIndexCSX"), - Self::SparseTensorIndexCSF => Some("SparseTensorIndexCSF"), - _ => None, - } - } + pub const NONE: Self = Self(0); + pub const SparseTensorIndexCOO: Self = Self(1); + pub const SparseMatrixIndexCSX: Self = Self(2); + pub const SparseTensorIndexCSF: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::SparseTensorIndexCOO, + Self::SparseMatrixIndexCSX, + Self::SparseTensorIndexCSF, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::SparseTensorIndexCOO => Some("SparseTensorIndexCOO"), + Self::SparseMatrixIndexCSX => Some("SparseMatrixIndexCSX"), + Self::SparseTensorIndexCSF => Some("SparseTensorIndexCSF"), + _ => None, + } + } } -impl std::fmt::Debug for SparseTensorIndex { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } +impl core::fmt::Debug for SparseTensorIndex { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } } -pub struct SparseTensorIndexUnionTableOffset {} impl<'a> flatbuffers::Follow<'a> for SparseTensorIndex { - type Inner = Self; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { flatbuffers::read_scalar_at::(buf, loc) }; - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for SparseTensorIndex { type Output = SparseTensorIndex; #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - unsafe { flatbuffers::emplace_scalar::(dst, self.0) }; + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); } } impl flatbuffers::EndianScalar for SparseTensorIndex { - #[inline] - fn to_little_endian(self) -> Self { - let b = u8::to_le(self.0); - Self(b) - } - #[inline] - fn from_little_endian(self) -> Self { - let b = u8::from_le(self.0); - Self(b) - } + type Scalar = u8; + #[inline] + fn to_little_endian(self) -> u8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for SparseTensorIndex { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - u8::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + u8::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for SparseTensorIndex {} +pub struct SparseTensorIndexUnionTableOffset {} + pub enum SparseTensorIndexCOOOffset {} #[derive(Copy, Clone, PartialEq)] @@ -254,111 +240,94 @@ pub enum SparseTensorIndexCOOOffset {} /// (row-major order), and it does not have duplicated entries. Otherwise, /// the indices may not be sorted, or may have duplicated entries. pub struct SparseTensorIndexCOO<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCOO<'a> { - type Inner = SparseTensorIndexCOO<'a>; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table { buf, loc }, - } - } + type Inner = SparseTensorIndexCOO<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> SparseTensorIndexCOO<'a> { - #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensorIndexCOO { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorIndexCOOArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorIndexCOOBuilder::new(_fbb); - if let Some(x) = args.indicesBuffer { - builder.add_indicesBuffer(x); - } - if let Some(x) = args.indicesStrides { - builder.add_indicesStrides(x); - } - if let Some(x) = args.indicesType { - builder.add_indicesType(x); - } - builder.add_isCanonical(args.isCanonical); - builder.finish() - } - - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 4; - pub const VT_INDICESSTRIDES: flatbuffers::VOffsetT = 6; - pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 8; - pub const VT_ISCANONICAL: flatbuffers::VOffsetT = 10; - - /// The type of values in indicesBuffer - #[inline] - pub fn indicesType(&self) -> Int<'a> { - self._tab - .get::>( - SparseTensorIndexCOO::VT_INDICESTYPE, - None, - ) - .unwrap() - } - /// Non-negative byte offsets to advance one value cell along each dimension - /// If omitted, default to row-major order (C-like). - #[inline] - pub fn indicesStrides(&self) -> Option> { - self._tab - .get::>>( - SparseTensorIndexCOO::VT_INDICESSTRIDES, - None, - ) - } - /// The location and size of the indices matrix's data - #[inline] - pub fn indicesBuffer(&self) -> &'a Buffer { - self._tab - .get::(SparseTensorIndexCOO::VT_INDICESBUFFER, None) - .unwrap() - } - /// This flag is true if and only if the indices matrix is sorted in - /// row-major order, and does not have duplicated entries. - /// This sort order is the same as of Tensorflow's SparseTensor, - /// but it is inverse order of SciPy's canonical coo_matrix - /// (SciPy employs column-major order for its coo_matrix). - #[inline] - pub fn isCanonical(&self) -> bool { - self._tab - .get::(SparseTensorIndexCOO::VT_ISCANONICAL, Some(false)) - .unwrap() - } + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 4; + pub const VT_INDICESSTRIDES: flatbuffers::VOffsetT = 6; + pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 8; + pub const VT_ISCANONICAL: flatbuffers::VOffsetT = 10; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensorIndexCOO { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorIndexCOOArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorIndexCOOBuilder::new(_fbb); + if let Some(x) = args.indicesBuffer { builder.add_indicesBuffer(x); } + if let Some(x) = args.indicesStrides { builder.add_indicesStrides(x); } + if let Some(x) = args.indicesType { builder.add_indicesType(x); } + builder.add_isCanonical(args.isCanonical); + builder.finish() + } + + + /// The type of values in indicesBuffer + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(SparseTensorIndexCOO::VT_INDICESTYPE, None).unwrap()} + } + /// Non-negative byte offsets to advance one value cell along each dimension + /// If omitted, default to row-major order (C-like). + #[inline] + pub fn indicesStrides(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensorIndexCOO::VT_INDICESSTRIDES, None)} + } + /// The location and size of the indices matrix's data + #[inline] + pub fn indicesBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensorIndexCOO::VT_INDICESBUFFER, None).unwrap()} + } + /// This flag is true if and only if the indices matrix is sorted in + /// row-major order, and does not have duplicated entries. + /// This sort order is the same as of Tensorflow's SparseTensor, + /// but it is inverse order of SciPy's canonical coo_matrix + /// (SciPy employs column-major order for its coo_matrix). + #[inline] + pub fn isCanonical(&self) -> bool { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensorIndexCOO::VT_ISCANONICAL, Some(false)).unwrap()} + } } impl flatbuffers::Verifiable for SparseTensorIndexCOO<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>( - &"indicesType", - Self::VT_INDICESTYPE, - true, - )? - .visit_field::>>( - &"indicesStrides", - Self::VT_INDICESSTRIDES, - false, - )? - .visit_field::(&"indicesBuffer", Self::VT_INDICESBUFFER, true)? - .visit_field::(&"isCanonical", Self::VT_ISCANONICAL, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? + .visit_field::>>("indicesStrides", Self::VT_INDICESSTRIDES, false)? + .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? + .visit_field::("isCanonical", Self::VT_ISCANONICAL, false)? + .finish(); + Ok(()) + } } pub struct SparseTensorIndexCOOArgs<'a> { pub indicesType: Option>>, @@ -367,239 +336,194 @@ pub struct SparseTensorIndexCOOArgs<'a> { pub isCanonical: bool, } impl<'a> Default for SparseTensorIndexCOOArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorIndexCOOArgs { - indicesType: None, // required field - indicesStrides: None, - indicesBuffer: None, // required field - isCanonical: false, - } - } + #[inline] + fn default() -> Self { + SparseTensorIndexCOOArgs { + indicesType: None, // required field + indicesStrides: None, + indicesBuffer: None, // required field + isCanonical: false, + } + } } + pub struct SparseTensorIndexCOOBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorIndexCOOBuilder<'a, 'b> { - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCOO::VT_INDICESTYPE, - indicesType, - ); - } - #[inline] - pub fn add_indicesStrides( - &mut self, - indicesStrides: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCOO::VT_INDICESSTRIDES, - indicesStrides, - ); - } - #[inline] - pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>( - SparseTensorIndexCOO::VT_INDICESBUFFER, - indicesBuffer, - ); - } - #[inline] - pub fn add_isCanonical(&mut self, isCanonical: bool) { - self.fbb_.push_slot::( - SparseTensorIndexCOO::VT_ISCANONICAL, - isCanonical, - false, - ); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> SparseTensorIndexCOOBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorIndexCOOBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_ - .required(o, SparseTensorIndexCOO::VT_INDICESTYPE, "indicesType"); - self.fbb_ - .required(o, SparseTensorIndexCOO::VT_INDICESBUFFER, "indicesBuffer"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCOO::VT_INDICESTYPE, indicesType); + } + #[inline] + pub fn add_indicesStrides(&mut self, indicesStrides: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCOO::VT_INDICESSTRIDES, indicesStrides); + } + #[inline] + pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>(SparseTensorIndexCOO::VT_INDICESBUFFER, indicesBuffer); + } + #[inline] + pub fn add_isCanonical(&mut self, isCanonical: bool) { + self.fbb_.push_slot::(SparseTensorIndexCOO::VT_ISCANONICAL, isCanonical, false); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorIndexCOOBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorIndexCOOBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, SparseTensorIndexCOO::VT_INDICESTYPE,"indicesType"); + self.fbb_.required(o, SparseTensorIndexCOO::VT_INDICESBUFFER,"indicesBuffer"); + flatbuffers::WIPOffset::new(o.value()) + } } -impl std::fmt::Debug for SparseTensorIndexCOO<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut ds = f.debug_struct("SparseTensorIndexCOO"); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesStrides", &self.indicesStrides()); - ds.field("indicesBuffer", &self.indicesBuffer()); - ds.field("isCanonical", &self.isCanonical()); - ds.finish() - } +impl core::fmt::Debug for SparseTensorIndexCOO<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensorIndexCOO"); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesStrides", &self.indicesStrides()); + ds.field("indicesBuffer", &self.indicesBuffer()); + ds.field("isCanonical", &self.isCanonical()); + ds.finish() + } } pub enum SparseMatrixIndexCSXOffset {} #[derive(Copy, Clone, PartialEq)] /// Compressed Sparse format, that is matrix-specific. pub struct SparseMatrixIndexCSX<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseMatrixIndexCSX<'a> { - type Inner = SparseMatrixIndexCSX<'a>; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table { buf, loc }, - } - } + type Inner = SparseMatrixIndexCSX<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> SparseMatrixIndexCSX<'a> { - #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseMatrixIndexCSX { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseMatrixIndexCSXArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseMatrixIndexCSXBuilder::new(_fbb); - if let Some(x) = args.indicesBuffer { - builder.add_indicesBuffer(x); - } - if let Some(x) = args.indicesType { - builder.add_indicesType(x); - } - if let Some(x) = args.indptrBuffer { - builder.add_indptrBuffer(x); - } - if let Some(x) = args.indptrType { - builder.add_indptrType(x); - } - builder.add_compressedAxis(args.compressedAxis); - builder.finish() - } - - pub const VT_COMPRESSEDAXIS: flatbuffers::VOffsetT = 4; - pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 6; - pub const VT_INDPTRBUFFER: flatbuffers::VOffsetT = 8; - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 10; - pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 12; - - /// Which axis, row or column, is compressed - #[inline] - pub fn compressedAxis(&self) -> SparseMatrixCompressedAxis { - self._tab - .get::( - SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, - Some(SparseMatrixCompressedAxis::Row), - ) - .unwrap() - } - /// The type of values in indptrBuffer - #[inline] - pub fn indptrType(&self) -> Int<'a> { - self._tab - .get::>( - SparseMatrixIndexCSX::VT_INDPTRTYPE, - None, - ) - .unwrap() - } - /// indptrBuffer stores the location and size of indptr array that - /// represents the range of the rows. - /// The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. - /// The length of this array is 1 + (the number of rows), and the type - /// of index value is long. - /// - /// For example, let X be the following 6x4 matrix: - /// ```text - /// X := [[0, 1, 2, 0], - /// [0, 0, 3, 0], - /// [0, 4, 0, 5], - /// [0, 0, 0, 0], - /// [6, 0, 7, 8], - /// [0, 9, 0, 0]]. - /// ``` - /// The array of non-zero values in X is: - /// ```text - /// values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. - /// ``` - /// And the indptr of X is: - /// ```text - /// indptr(X) = [0, 2, 3, 5, 5, 8, 10]. - /// ``` - #[inline] - pub fn indptrBuffer(&self) -> &'a Buffer { - self._tab - .get::(SparseMatrixIndexCSX::VT_INDPTRBUFFER, None) - .unwrap() - } - /// The type of values in indicesBuffer - #[inline] - pub fn indicesType(&self) -> Int<'a> { - self._tab - .get::>( - SparseMatrixIndexCSX::VT_INDICESTYPE, - None, - ) - .unwrap() - } - /// indicesBuffer stores the location and size of the array that - /// contains the column indices of the corresponding non-zero values. - /// The type of index value is long. - /// - /// For example, the indices of the above X is: - /// ```text - /// indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. - /// ``` - /// Note that the indices are sorted in lexicographical order for each row. - #[inline] - pub fn indicesBuffer(&self) -> &'a Buffer { - self._tab - .get::(SparseMatrixIndexCSX::VT_INDICESBUFFER, None) - .unwrap() - } + pub const VT_COMPRESSEDAXIS: flatbuffers::VOffsetT = 4; + pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 6; + pub const VT_INDPTRBUFFER: flatbuffers::VOffsetT = 8; + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 10; + pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseMatrixIndexCSX { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseMatrixIndexCSXArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseMatrixIndexCSXBuilder::new(_fbb); + if let Some(x) = args.indicesBuffer { builder.add_indicesBuffer(x); } + if let Some(x) = args.indicesType { builder.add_indicesType(x); } + if let Some(x) = args.indptrBuffer { builder.add_indptrBuffer(x); } + if let Some(x) = args.indptrType { builder.add_indptrType(x); } + builder.add_compressedAxis(args.compressedAxis); + builder.finish() + } + + + /// Which axis, row or column, is compressed + #[inline] + pub fn compressedAxis(&self) -> SparseMatrixCompressedAxis { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, Some(SparseMatrixCompressedAxis::Row)).unwrap()} + } + /// The type of values in indptrBuffer + #[inline] + pub fn indptrType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(SparseMatrixIndexCSX::VT_INDPTRTYPE, None).unwrap()} + } + /// indptrBuffer stores the location and size of indptr array that + /// represents the range of the rows. + /// The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. + /// The length of this array is 1 + (the number of rows), and the type + /// of index value is long. + /// + /// For example, let X be the following 6x4 matrix: + /// ```text + /// X := [[0, 1, 2, 0], + /// [0, 0, 3, 0], + /// [0, 4, 0, 5], + /// [0, 0, 0, 0], + /// [6, 0, 7, 8], + /// [0, 9, 0, 0]]. + /// ``` + /// The array of non-zero values in X is: + /// ```text + /// values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. + /// ``` + /// And the indptr of X is: + /// ```text + /// indptr(X) = [0, 2, 3, 5, 5, 8, 10]. + /// ``` + #[inline] + pub fn indptrBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_INDPTRBUFFER, None).unwrap()} + } + /// The type of values in indicesBuffer + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(SparseMatrixIndexCSX::VT_INDICESTYPE, None).unwrap()} + } + /// indicesBuffer stores the location and size of the array that + /// contains the column indices of the corresponding non-zero values. + /// The type of index value is long. + /// + /// For example, the indices of the above X is: + /// ```text + /// indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. + /// ``` + /// Note that the indices are sorted in lexicographical order for each row. + #[inline] + pub fn indicesBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_INDICESBUFFER, None).unwrap()} + } } impl flatbuffers::Verifiable for SparseMatrixIndexCSX<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::( - &"compressedAxis", - Self::VT_COMPRESSEDAXIS, - false, - )? - .visit_field::>( - &"indptrType", - Self::VT_INDPTRTYPE, - true, - )? - .visit_field::(&"indptrBuffer", Self::VT_INDPTRBUFFER, true)? - .visit_field::>( - &"indicesType", - Self::VT_INDICESTYPE, - true, - )? - .visit_field::(&"indicesBuffer", Self::VT_INDICESBUFFER, true)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("compressedAxis", Self::VT_COMPRESSEDAXIS, false)? + .visit_field::>("indptrType", Self::VT_INDPTRTYPE, true)? + .visit_field::("indptrBuffer", Self::VT_INDPTRBUFFER, true)? + .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? + .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? + .finish(); + Ok(()) + } } pub struct SparseMatrixIndexCSXArgs<'a> { pub compressedAxis: SparseMatrixCompressedAxis, @@ -609,295 +533,230 @@ pub struct SparseMatrixIndexCSXArgs<'a> { pub indicesBuffer: Option<&'a Buffer>, } impl<'a> Default for SparseMatrixIndexCSXArgs<'a> { - #[inline] - fn default() -> Self { - SparseMatrixIndexCSXArgs { - compressedAxis: SparseMatrixCompressedAxis::Row, - indptrType: None, // required field - indptrBuffer: None, // required field - indicesType: None, // required field - indicesBuffer: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseMatrixIndexCSXArgs { + compressedAxis: SparseMatrixCompressedAxis::Row, + indptrType: None, // required field + indptrBuffer: None, // required field + indicesType: None, // required field + indicesBuffer: None, // required field + } + } } + pub struct SparseMatrixIndexCSXBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseMatrixIndexCSXBuilder<'a, 'b> { - #[inline] - pub fn add_compressedAxis(&mut self, compressedAxis: SparseMatrixCompressedAxis) { - self.fbb_.push_slot::( - SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, - compressedAxis, - SparseMatrixCompressedAxis::Row, - ); - } - #[inline] - pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - SparseMatrixIndexCSX::VT_INDPTRTYPE, - indptrType, - ); - } - #[inline] - pub fn add_indptrBuffer(&mut self, indptrBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>( - SparseMatrixIndexCSX::VT_INDPTRBUFFER, - indptrBuffer, - ); - } - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - SparseMatrixIndexCSX::VT_INDICESTYPE, - indicesType, - ); - } - #[inline] - pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>( - SparseMatrixIndexCSX::VT_INDICESBUFFER, - indicesBuffer, - ); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> SparseMatrixIndexCSXBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseMatrixIndexCSXBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_ - .required(o, SparseMatrixIndexCSX::VT_INDPTRTYPE, "indptrType"); - self.fbb_ - .required(o, SparseMatrixIndexCSX::VT_INDPTRBUFFER, "indptrBuffer"); - self.fbb_ - .required(o, SparseMatrixIndexCSX::VT_INDICESTYPE, "indicesType"); - self.fbb_ - .required(o, SparseMatrixIndexCSX::VT_INDICESBUFFER, "indicesBuffer"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_compressedAxis(&mut self, compressedAxis: SparseMatrixCompressedAxis) { + self.fbb_.push_slot::(SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, compressedAxis, SparseMatrixCompressedAxis::Row); + } + #[inline] + pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseMatrixIndexCSX::VT_INDPTRTYPE, indptrType); + } + #[inline] + pub fn add_indptrBuffer(&mut self, indptrBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDPTRBUFFER, indptrBuffer); + } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseMatrixIndexCSX::VT_INDICESTYPE, indicesType); + } + #[inline] + pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDICESBUFFER, indicesBuffer); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseMatrixIndexCSXBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseMatrixIndexCSXBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDPTRTYPE,"indptrType"); + self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDPTRBUFFER,"indptrBuffer"); + self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDICESTYPE,"indicesType"); + self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDICESBUFFER,"indicesBuffer"); + flatbuffers::WIPOffset::new(o.value()) + } } -impl std::fmt::Debug for SparseMatrixIndexCSX<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut ds = f.debug_struct("SparseMatrixIndexCSX"); - ds.field("compressedAxis", &self.compressedAxis()); - ds.field("indptrType", &self.indptrType()); - ds.field("indptrBuffer", &self.indptrBuffer()); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesBuffer", &self.indicesBuffer()); - ds.finish() - } +impl core::fmt::Debug for SparseMatrixIndexCSX<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseMatrixIndexCSX"); + ds.field("compressedAxis", &self.compressedAxis()); + ds.field("indptrType", &self.indptrType()); + ds.field("indptrBuffer", &self.indptrBuffer()); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesBuffer", &self.indicesBuffer()); + ds.finish() + } } pub enum SparseTensorIndexCSFOffset {} #[derive(Copy, Clone, PartialEq)] /// Compressed Sparse Fiber (CSF) sparse tensor index. pub struct SparseTensorIndexCSF<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCSF<'a> { - type Inner = SparseTensorIndexCSF<'a>; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table { buf, loc }, - } - } + type Inner = SparseTensorIndexCSF<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> SparseTensorIndexCSF<'a> { - #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensorIndexCSF { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorIndexCSFArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorIndexCSFBuilder::new(_fbb); - if let Some(x) = args.axisOrder { - builder.add_axisOrder(x); - } - if let Some(x) = args.indicesBuffers { - builder.add_indicesBuffers(x); - } - if let Some(x) = args.indicesType { - builder.add_indicesType(x); - } - if let Some(x) = args.indptrBuffers { - builder.add_indptrBuffers(x); - } - if let Some(x) = args.indptrType { - builder.add_indptrType(x); - } - builder.finish() - } - - pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 4; - pub const VT_INDPTRBUFFERS: flatbuffers::VOffsetT = 6; - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 8; - pub const VT_INDICESBUFFERS: flatbuffers::VOffsetT = 10; - pub const VT_AXISORDER: flatbuffers::VOffsetT = 12; - - /// CSF is a generalization of compressed sparse row (CSR) index. - /// See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) - /// - /// CSF index recursively compresses each dimension of a tensor into a set - /// of prefix trees. Each path from a root to leaf forms one tensor - /// non-zero index. CSF is implemented with two arrays of buffers and one - /// arrays of integers. - /// - /// For example, let X be a 2x3x4x5 tensor and let it have the following - /// 8 non-zero values: - /// ```text - /// X[0, 0, 0, 1] := 1 - /// X[0, 0, 0, 2] := 2 - /// X[0, 1, 0, 0] := 3 - /// X[0, 1, 0, 2] := 4 - /// X[0, 1, 1, 0] := 5 - /// X[1, 1, 1, 0] := 6 - /// X[1, 1, 1, 1] := 7 - /// X[1, 1, 1, 2] := 8 - /// ``` - /// As a prefix tree this would be represented as: - /// ```text - /// 0 1 - /// / \ | - /// 0 1 1 - /// / / \ | - /// 0 0 1 1 - /// /| /| | /| | - /// 1 2 0 2 0 0 1 2 - /// ``` - /// The type of values in indptrBuffers - #[inline] - pub fn indptrType(&self) -> Int<'a> { - self._tab - .get::>( - SparseTensorIndexCSF::VT_INDPTRTYPE, - None, - ) - .unwrap() - } - /// indptrBuffers stores the sparsity structure. - /// Each two consecutive dimensions in a tensor correspond to a buffer in - /// indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` - /// and `indptrBuffers[dim][i + 1]` signify a range of nodes in - /// `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. - /// - /// For example, the indptrBuffers for the above X is: - /// ```text - /// indptrBuffer(X) = [ - /// [0, 2, 3], - /// [0, 1, 3, 4], - /// [0, 2, 4, 5, 8] - /// ]. - /// ``` - #[inline] - pub fn indptrBuffers(&self) -> &'a [Buffer] { - self._tab - .get::>>( - SparseTensorIndexCSF::VT_INDPTRBUFFERS, - None, - ) - .map(|v| v.safe_slice()) - .unwrap() - } - /// The type of values in indicesBuffers - #[inline] - pub fn indicesType(&self) -> Int<'a> { - self._tab - .get::>( - SparseTensorIndexCSF::VT_INDICESTYPE, - None, - ) - .unwrap() - } - /// indicesBuffers stores values of nodes. - /// Each tensor dimension corresponds to a buffer in indicesBuffers. - /// For example, the indicesBuffers for the above X is: - /// ```text - /// indicesBuffer(X) = [ - /// [0, 1], - /// [0, 1, 1], - /// [0, 0, 1, 1], - /// [1, 2, 0, 2, 0, 0, 1, 2] - /// ]. - /// ``` - #[inline] - pub fn indicesBuffers(&self) -> &'a [Buffer] { - self._tab - .get::>>( - SparseTensorIndexCSF::VT_INDICESBUFFERS, - None, - ) - .map(|v| v.safe_slice()) - .unwrap() - } - /// axisOrder stores the sequence in which dimensions were traversed to - /// produce the prefix tree. - /// For example, the axisOrder for the above X is: - /// ```text - /// axisOrder(X) = [0, 1, 2, 3]. - /// ``` - #[inline] - pub fn axisOrder(&self) -> flatbuffers::Vector<'a, i32> { - self._tab - .get::>>( - SparseTensorIndexCSF::VT_AXISORDER, - None, - ) - .unwrap() - } + pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 4; + pub const VT_INDPTRBUFFERS: flatbuffers::VOffsetT = 6; + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 8; + pub const VT_INDICESBUFFERS: flatbuffers::VOffsetT = 10; + pub const VT_AXISORDER: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensorIndexCSF { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorIndexCSFArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorIndexCSFBuilder::new(_fbb); + if let Some(x) = args.axisOrder { builder.add_axisOrder(x); } + if let Some(x) = args.indicesBuffers { builder.add_indicesBuffers(x); } + if let Some(x) = args.indicesType { builder.add_indicesType(x); } + if let Some(x) = args.indptrBuffers { builder.add_indptrBuffers(x); } + if let Some(x) = args.indptrType { builder.add_indptrType(x); } + builder.finish() + } + + + /// CSF is a generalization of compressed sparse row (CSR) index. + /// See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) + /// + /// CSF index recursively compresses each dimension of a tensor into a set + /// of prefix trees. Each path from a root to leaf forms one tensor + /// non-zero index. CSF is implemented with two arrays of buffers and one + /// arrays of integers. + /// + /// For example, let X be a 2x3x4x5 tensor and let it have the following + /// 8 non-zero values: + /// ```text + /// X[0, 0, 0, 1] := 1 + /// X[0, 0, 0, 2] := 2 + /// X[0, 1, 0, 0] := 3 + /// X[0, 1, 0, 2] := 4 + /// X[0, 1, 1, 0] := 5 + /// X[1, 1, 1, 0] := 6 + /// X[1, 1, 1, 1] := 7 + /// X[1, 1, 1, 2] := 8 + /// ``` + /// As a prefix tree this would be represented as: + /// ```text + /// 0 1 + /// / \ | + /// 0 1 1 + /// / / \ | + /// 0 0 1 1 + /// /| /| | /| | + /// 1 2 0 2 0 0 1 2 + /// ``` + /// The type of values in indptrBuffers + #[inline] + pub fn indptrType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(SparseTensorIndexCSF::VT_INDPTRTYPE, None).unwrap()} + } + /// indptrBuffers stores the sparsity structure. + /// Each two consecutive dimensions in a tensor correspond to a buffer in + /// indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` + /// and `indptrBuffers[dim][i + 1]` signify a range of nodes in + /// `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. + /// + /// For example, the indptrBuffers for the above X is: + /// ```text + /// indptrBuffer(X) = [ + /// [0, 2, 3], + /// [0, 1, 3, 4], + /// [0, 2, 4, 5, 8] + /// ]. + /// ``` + #[inline] + pub fn indptrBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_INDPTRBUFFERS, None).unwrap()} + } + /// The type of values in indicesBuffers + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(SparseTensorIndexCSF::VT_INDICESTYPE, None).unwrap()} + } + /// indicesBuffers stores values of nodes. + /// Each tensor dimension corresponds to a buffer in indicesBuffers. + /// For example, the indicesBuffers for the above X is: + /// ```text + /// indicesBuffer(X) = [ + /// [0, 1], + /// [0, 1, 1], + /// [0, 0, 1, 1], + /// [1, 2, 0, 2, 0, 0, 1, 2] + /// ]. + /// ``` + #[inline] + pub fn indicesBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_INDICESBUFFERS, None).unwrap()} + } + /// axisOrder stores the sequence in which dimensions were traversed to + /// produce the prefix tree. + /// For example, the axisOrder for the above X is: + /// ```text + /// axisOrder(X) = [0, 1, 2, 3]. + /// ``` + #[inline] + pub fn axisOrder(&self) -> flatbuffers::Vector<'a, i32> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_AXISORDER, None).unwrap()} + } } impl flatbuffers::Verifiable for SparseTensorIndexCSF<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>( - &"indptrType", - Self::VT_INDPTRTYPE, - true, - )? - .visit_field::>>( - &"indptrBuffers", - Self::VT_INDPTRBUFFERS, - true, - )? - .visit_field::>( - &"indicesType", - Self::VT_INDICESTYPE, - true, - )? - .visit_field::>>( - &"indicesBuffers", - Self::VT_INDICESBUFFERS, - true, - )? - .visit_field::>>( - &"axisOrder", - Self::VT_AXISORDER, - true, - )? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("indptrType", Self::VT_INDPTRTYPE, true)? + .visit_field::>>("indptrBuffers", Self::VT_INDPTRBUFFERS, true)? + .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? + .visit_field::>>("indicesBuffers", Self::VT_INDICESBUFFERS, true)? + .visit_field::>>("axisOrder", Self::VT_AXISORDER, true)? + .finish(); + Ok(()) + } } pub struct SparseTensorIndexCSFArgs<'a> { pub indptrType: Option>>, @@ -907,500 +766,521 @@ pub struct SparseTensorIndexCSFArgs<'a> { pub axisOrder: Option>>, } impl<'a> Default for SparseTensorIndexCSFArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorIndexCSFArgs { - indptrType: None, // required field - indptrBuffers: None, // required field - indicesType: None, // required field - indicesBuffers: None, // required field - axisOrder: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseTensorIndexCSFArgs { + indptrType: None, // required field + indptrBuffers: None, // required field + indicesType: None, // required field + indicesBuffers: None, // required field + axisOrder: None, // required field + } + } } + pub struct SparseTensorIndexCSFBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorIndexCSFBuilder<'a, 'b> { - #[inline] - pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCSF::VT_INDPTRTYPE, - indptrType, - ); - } - #[inline] - pub fn add_indptrBuffers( - &mut self, - indptrBuffers: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCSF::VT_INDPTRBUFFERS, - indptrBuffers, - ); - } - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCSF::VT_INDICESTYPE, - indicesType, - ); - } - #[inline] - pub fn add_indicesBuffers( - &mut self, - indicesBuffers: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCSF::VT_INDICESBUFFERS, - indicesBuffers, - ); - } - #[inline] - pub fn add_axisOrder( - &mut self, - axisOrder: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - SparseTensorIndexCSF::VT_AXISORDER, - axisOrder, - ); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> SparseTensorIndexCSFBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorIndexCSFBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_ - .required(o, SparseTensorIndexCSF::VT_INDPTRTYPE, "indptrType"); - self.fbb_ - .required(o, SparseTensorIndexCSF::VT_INDPTRBUFFERS, "indptrBuffers"); - self.fbb_ - .required(o, SparseTensorIndexCSF::VT_INDICESTYPE, "indicesType"); - self.fbb_ - .required(o, SparseTensorIndexCSF::VT_INDICESBUFFERS, "indicesBuffers"); - self.fbb_ - .required(o, SparseTensorIndexCSF::VT_AXISORDER, "axisOrder"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDPTRTYPE, indptrType); + } + #[inline] + pub fn add_indptrBuffers(&mut self, indptrBuffers: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDPTRBUFFERS, indptrBuffers); + } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDICESTYPE, indicesType); + } + #[inline] + pub fn add_indicesBuffers(&mut self, indicesBuffers: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDICESBUFFERS, indicesBuffers); + } + #[inline] + pub fn add_axisOrder(&mut self, axisOrder: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_AXISORDER, axisOrder); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorIndexCSFBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorIndexCSFBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, SparseTensorIndexCSF::VT_INDPTRTYPE,"indptrType"); + self.fbb_.required(o, SparseTensorIndexCSF::VT_INDPTRBUFFERS,"indptrBuffers"); + self.fbb_.required(o, SparseTensorIndexCSF::VT_INDICESTYPE,"indicesType"); + self.fbb_.required(o, SparseTensorIndexCSF::VT_INDICESBUFFERS,"indicesBuffers"); + self.fbb_.required(o, SparseTensorIndexCSF::VT_AXISORDER,"axisOrder"); + flatbuffers::WIPOffset::new(o.value()) + } } -impl std::fmt::Debug for SparseTensorIndexCSF<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut ds = f.debug_struct("SparseTensorIndexCSF"); - ds.field("indptrType", &self.indptrType()); - ds.field("indptrBuffers", &self.indptrBuffers()); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesBuffers", &self.indicesBuffers()); - ds.field("axisOrder", &self.axisOrder()); - ds.finish() - } +impl core::fmt::Debug for SparseTensorIndexCSF<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensorIndexCSF"); + ds.field("indptrType", &self.indptrType()); + ds.field("indptrBuffers", &self.indptrBuffers()); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesBuffers", &self.indicesBuffers()); + ds.field("axisOrder", &self.axisOrder()); + ds.finish() + } } pub enum SparseTensorOffset {} #[derive(Copy, Clone, PartialEq)] pub struct SparseTensor<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensor<'a> { - type Inner = SparseTensor<'a>; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table { buf, loc }, - } - } + type Inner = SparseTensor<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } } impl<'a> SparseTensor<'a> { - #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensor { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorArgs<'args>, - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorBuilder::new(_fbb); - builder.add_non_zero_length(args.non_zero_length); - if let Some(x) = args.data { - builder.add_data(x); - } - if let Some(x) = args.sparseIndex { - builder.add_sparseIndex(x); - } - if let Some(x) = args.shape { - builder.add_shape(x); - } - if let Some(x) = args.type_ { - builder.add_type_(x); - } - builder.add_sparseIndex_type(args.sparseIndex_type); - builder.add_type_type(args.type_type); - builder.finish() - } - - pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_TYPE_: flatbuffers::VOffsetT = 6; - pub const VT_SHAPE: flatbuffers::VOffsetT = 8; - pub const VT_NON_ZERO_LENGTH: flatbuffers::VOffsetT = 10; - pub const VT_SPARSEINDEX_TYPE: flatbuffers::VOffsetT = 12; - pub const VT_SPARSEINDEX: flatbuffers::VOffsetT = 14; - pub const VT_DATA: flatbuffers::VOffsetT = 16; - - #[inline] - pub fn type_type(&self) -> Type { - self._tab - .get::(SparseTensor::VT_TYPE_TYPE, Some(Type::NONE)) - .unwrap() - } - /// The type of data contained in a value cell. - /// Currently only fixed-width value types are supported, - /// no strings or nested types. - #[inline] - pub fn type_(&self) -> flatbuffers::Table<'a> { - self._tab - .get::>>( - SparseTensor::VT_TYPE_, - None, - ) - .unwrap() - } - /// The dimensions of the tensor, optionally named. - #[inline] - pub fn shape( - &self, - ) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>> { - self._tab - .get::>, - >>(SparseTensor::VT_SHAPE, None) - .unwrap() - } - /// The number of non-zero values in a sparse tensor. - #[inline] - pub fn non_zero_length(&self) -> i64 { - self._tab - .get::(SparseTensor::VT_NON_ZERO_LENGTH, Some(0)) - .unwrap() - } - #[inline] - pub fn sparseIndex_type(&self) -> SparseTensorIndex { - self._tab - .get::( - SparseTensor::VT_SPARSEINDEX_TYPE, - Some(SparseTensorIndex::NONE), - ) - .unwrap() - } - /// Sparse tensor index - #[inline] - pub fn sparseIndex(&self) -> flatbuffers::Table<'a> { - self._tab - .get::>>( - SparseTensor::VT_SPARSEINDEX, - None, - ) - .unwrap() - } - /// The location and size of the tensor's data - #[inline] - pub fn data(&self) -> &'a Buffer { - self._tab - .get::(SparseTensor::VT_DATA, None) - .unwrap() - } - #[inline] - #[allow(non_snake_case)] - pub fn type_as_null(&self) -> Option> { - if self.type_type() == Type::Null { - let u = self.type_(); - Some(Null::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_int(&self) -> Option> { - if self.type_type() == Type::Int { - let u = self.type_(); - Some(Int::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_floating_point(&self) -> Option> { - if self.type_type() == Type::FloatingPoint { - let u = self.type_(); - Some(FloatingPoint::init_from_table(u)) - } else { - None - } - } + pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_TYPE_: flatbuffers::VOffsetT = 6; + pub const VT_SHAPE: flatbuffers::VOffsetT = 8; + pub const VT_NON_ZERO_LENGTH: flatbuffers::VOffsetT = 10; + pub const VT_SPARSEINDEX_TYPE: flatbuffers::VOffsetT = 12; + pub const VT_SPARSEINDEX: flatbuffers::VOffsetT = 14; + pub const VT_DATA: flatbuffers::VOffsetT = 16; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensor { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorBuilder::new(_fbb); + builder.add_non_zero_length(args.non_zero_length); + if let Some(x) = args.data { builder.add_data(x); } + if let Some(x) = args.sparseIndex { builder.add_sparseIndex(x); } + if let Some(x) = args.shape { builder.add_shape(x); } + if let Some(x) = args.type_ { builder.add_type_(x); } + builder.add_sparseIndex_type(args.sparseIndex_type); + builder.add_type_type(args.type_type); + builder.finish() + } + + + #[inline] + pub fn type_type(&self) -> Type { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensor::VT_TYPE_TYPE, Some(Type::NONE)).unwrap()} + } + /// The type of data contained in a value cell. + /// Currently only fixed-width value types are supported, + /// no strings or nested types. + #[inline] + pub fn type_(&self) -> flatbuffers::Table<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensor::VT_TYPE_, None).unwrap()} + } + /// The dimensions of the tensor, optionally named. + #[inline] + pub fn shape(&self) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(SparseTensor::VT_SHAPE, None).unwrap()} + } + /// The number of non-zero values in a sparse tensor. + #[inline] + pub fn non_zero_length(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensor::VT_NON_ZERO_LENGTH, Some(0)).unwrap()} + } + #[inline] + pub fn sparseIndex_type(&self) -> SparseTensorIndex { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensor::VT_SPARSEINDEX_TYPE, Some(SparseTensorIndex::NONE)).unwrap()} + } + /// Sparse tensor index + #[inline] + pub fn sparseIndex(&self) -> flatbuffers::Table<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(SparseTensor::VT_SPARSEINDEX, None).unwrap()} + } + /// The location and size of the tensor's data + #[inline] + pub fn data(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(SparseTensor::VT_DATA, None).unwrap()} + } + #[inline] + #[allow(non_snake_case)] + pub fn type_as_null(&self) -> Option> { + if self.type_type() == Type::Null { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Null::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_int(&self) -> Option> { + if self.type_type() == Type::Int { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Int::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_floating_point(&self) -> Option> { + if self.type_type() == Type::FloatingPoint { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FloatingPoint::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_binary(&self) -> Option> { + if self.type_type() == Type::Binary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Binary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_utf_8(&self) -> Option> { + if self.type_type() == Type::Utf8 { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Utf8::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_bool(&self) -> Option> { + if self.type_type() == Type::Bool { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Bool::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_decimal(&self) -> Option> { + if self.type_type() == Type::Decimal { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Decimal::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_date(&self) -> Option> { + if self.type_type() == Type::Date { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Date::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_time(&self) -> Option> { + if self.type_type() == Type::Time { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Time::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_timestamp(&self) -> Option> { + if self.type_type() == Type::Timestamp { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Timestamp::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_interval(&self) -> Option> { + if self.type_type() == Type::Interval { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Interval::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_list(&self) -> Option> { + if self.type_type() == Type::List { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { List::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_struct_(&self) -> Option> { + if self.type_type() == Type::Struct_ { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Struct_::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_union(&self) -> Option> { + if self.type_type() == Type::Union { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Union::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_fixed_size_binary(&self) -> Option> { + if self.type_type() == Type::FixedSizeBinary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeBinary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_fixed_size_list(&self) -> Option> { + if self.type_type() == Type::FixedSizeList { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeList::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_map(&self) -> Option> { + if self.type_type() == Type::Map { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Map::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_duration(&self) -> Option> { + if self.type_type() == Type::Duration { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Duration::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_binary(&self) -> Option> { + if self.type_type() == Type::LargeBinary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeBinary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_utf_8(&self) -> Option> { + if self.type_type() == Type::LargeUtf8 { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeUtf8::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_list(&self) -> Option> { + if self.type_type() == Type::LargeList { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeList::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_tensor_index_coo(&self) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCOO { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseTensorIndexCOO::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_matrix_index_csx(&self) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseMatrixIndexCSX { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseMatrixIndexCSX::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_tensor_index_csf(&self) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCSF { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseTensorIndexCSF::init_from_table(u) }) + } else { + None + } + } - #[inline] - #[allow(non_snake_case)] - pub fn type_as_binary(&self) -> Option> { - if self.type_type() == Type::Binary { - let u = self.type_(); - Some(Binary::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_utf_8(&self) -> Option> { - if self.type_type() == Type::Utf8 { - let u = self.type_(); - Some(Utf8::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_bool(&self) -> Option> { - if self.type_type() == Type::Bool { - let u = self.type_(); - Some(Bool::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_decimal(&self) -> Option> { - if self.type_type() == Type::Decimal { - let u = self.type_(); - Some(Decimal::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_date(&self) -> Option> { - if self.type_type() == Type::Date { - let u = self.type_(); - Some(Date::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_time(&self) -> Option> { - if self.type_type() == Type::Time { - let u = self.type_(); - Some(Time::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_timestamp(&self) -> Option> { - if self.type_type() == Type::Timestamp { - let u = self.type_(); - Some(Timestamp::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_interval(&self) -> Option> { - if self.type_type() == Type::Interval { - let u = self.type_(); - Some(Interval::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_list(&self) -> Option> { - if self.type_type() == Type::List { - let u = self.type_(); - Some(List::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_struct_(&self) -> Option> { - if self.type_type() == Type::Struct_ { - let u = self.type_(); - Some(Struct_::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_union(&self) -> Option> { - if self.type_type() == Type::Union { - let u = self.type_(); - Some(Union::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_fixed_size_binary(&self) -> Option> { - if self.type_type() == Type::FixedSizeBinary { - let u = self.type_(); - Some(FixedSizeBinary::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_fixed_size_list(&self) -> Option> { - if self.type_type() == Type::FixedSizeList { - let u = self.type_(); - Some(FixedSizeList::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_map(&self) -> Option> { - if self.type_type() == Type::Map { - let u = self.type_(); - Some(Map::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_duration(&self) -> Option> { - if self.type_type() == Type::Duration { - let u = self.type_(); - Some(Duration::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_binary(&self) -> Option> { - if self.type_type() == Type::LargeBinary { - let u = self.type_(); - Some(LargeBinary::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_utf_8(&self) -> Option> { - if self.type_type() == Type::LargeUtf8 { - let u = self.type_(); - Some(LargeUtf8::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_list(&self) -> Option> { - if self.type_type() == Type::LargeList { - let u = self.type_(); - Some(LargeList::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_tensor_index_coo( - &self, - ) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCOO { - let u = self.sparseIndex(); - Some(SparseTensorIndexCOO::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_matrix_index_csx( - &self, - ) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseMatrixIndexCSX { - let u = self.sparseIndex(); - Some(SparseMatrixIndexCSX::init_from_table(u)) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_tensor_index_csf( - &self, - ) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCSF { - let u = self.sparseIndex(); - Some(SparseTensorIndexCSF::init_from_table(u)) - } else { - None - } - } } impl flatbuffers::Verifiable for SparseTensor<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_union::(&"type_type", Self::VT_TYPE_TYPE, &"type_", Self::VT_TYPE_, true, |key, v, pos| { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_union::("type_type", Self::VT_TYPE_TYPE, "type_", Self::VT_TYPE_, true, |key, v, pos| { match key { Type::Null => v.verify_union_variant::>("Type::Null", pos), Type::Int => v.verify_union_variant::>("Type::Int", pos), @@ -1426,9 +1306,9 @@ impl flatbuffers::Verifiable for SparseTensor<'_> { _ => Ok(()), } })? - .visit_field::>>>(&"shape", Self::VT_SHAPE, true)? - .visit_field::(&"non_zero_length", Self::VT_NON_ZERO_LENGTH, false)? - .visit_union::(&"sparseIndex_type", Self::VT_SPARSEINDEX_TYPE, &"sparseIndex", Self::VT_SPARSEINDEX, true, |key, v, pos| { + .visit_field::>>>("shape", Self::VT_SHAPE, true)? + .visit_field::("non_zero_length", Self::VT_NON_ZERO_LENGTH, false)? + .visit_union::("sparseIndex_type", Self::VT_SPARSEINDEX_TYPE, "sparseIndex", Self::VT_SPARSEINDEX, true, |key, v, pos| { match key { SparseTensorIndex::SparseTensorIndexCOO => v.verify_union_variant::>("SparseTensorIndex::SparseTensorIndexCOO", pos), SparseTensorIndex::SparseMatrixIndexCSX => v.verify_union_variant::>("SparseTensorIndex::SparseMatrixIndexCSX", pos), @@ -1436,391 +1316,278 @@ impl flatbuffers::Verifiable for SparseTensor<'_> { _ => Ok(()), } })? - .visit_field::(&"data", Self::VT_DATA, true)? + .visit_field::("data", Self::VT_DATA, true)? .finish(); - Ok(()) - } + Ok(()) + } } pub struct SparseTensorArgs<'a> { pub type_type: Type, pub type_: Option>, - pub shape: Option< - flatbuffers::WIPOffset< - flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, - >, - >, + pub shape: Option>>>>, pub non_zero_length: i64, pub sparseIndex_type: SparseTensorIndex, pub sparseIndex: Option>, pub data: Option<&'a Buffer>, } impl<'a> Default for SparseTensorArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorArgs { - type_type: Type::NONE, - type_: None, // required field - shape: None, // required field - non_zero_length: 0, - sparseIndex_type: SparseTensorIndex::NONE, - sparseIndex: None, // required field - data: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseTensorArgs { + type_type: Type::NONE, + type_: None, // required field + shape: None, // required field + non_zero_length: 0, + sparseIndex_type: SparseTensorIndex::NONE, + sparseIndex: None, // required field + data: None, // required field + } + } } + pub struct SparseTensorBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorBuilder<'a, 'b> { - #[inline] - pub fn add_type_type(&mut self, type_type: Type) { - self.fbb_ - .push_slot::(SparseTensor::VT_TYPE_TYPE, type_type, Type::NONE); - } - #[inline] - pub fn add_type_( - &mut self, - type_: flatbuffers::WIPOffset, - ) { - self.fbb_ - .push_slot_always::>(SparseTensor::VT_TYPE_, type_); - } - #[inline] - pub fn add_shape( - &mut self, - shape: flatbuffers::WIPOffset< - flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, - >, - ) { - self.fbb_ - .push_slot_always::>(SparseTensor::VT_SHAPE, shape); - } - #[inline] - pub fn add_non_zero_length(&mut self, non_zero_length: i64) { - self.fbb_ - .push_slot::(SparseTensor::VT_NON_ZERO_LENGTH, non_zero_length, 0); - } - #[inline] - pub fn add_sparseIndex_type(&mut self, sparseIndex_type: SparseTensorIndex) { - self.fbb_.push_slot::( - SparseTensor::VT_SPARSEINDEX_TYPE, - sparseIndex_type, - SparseTensorIndex::NONE, - ); - } - #[inline] - pub fn add_sparseIndex( - &mut self, - sparseIndex: flatbuffers::WIPOffset, - ) { - self.fbb_.push_slot_always::>( - SparseTensor::VT_SPARSEINDEX, - sparseIndex, - ); - } - #[inline] - pub fn add_data(&mut self, data: &Buffer) { - self.fbb_ - .push_slot_always::<&Buffer>(SparseTensor::VT_DATA, data); - } - #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - ) -> SparseTensorBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_.required(o, SparseTensor::VT_TYPE_, "type_"); - self.fbb_.required(o, SparseTensor::VT_SHAPE, "shape"); - self.fbb_ - .required(o, SparseTensor::VT_SPARSEINDEX, "sparseIndex"); - self.fbb_.required(o, SparseTensor::VT_DATA, "data"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_type_type(&mut self, type_type: Type) { + self.fbb_.push_slot::(SparseTensor::VT_TYPE_TYPE, type_type, Type::NONE); + } + #[inline] + pub fn add_type_(&mut self, type_: flatbuffers::WIPOffset) { + self.fbb_.push_slot_always::>(SparseTensor::VT_TYPE_, type_); + } + #[inline] + pub fn add_shape(&mut self, shape: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(SparseTensor::VT_SHAPE, shape); + } + #[inline] + pub fn add_non_zero_length(&mut self, non_zero_length: i64) { + self.fbb_.push_slot::(SparseTensor::VT_NON_ZERO_LENGTH, non_zero_length, 0); + } + #[inline] + pub fn add_sparseIndex_type(&mut self, sparseIndex_type: SparseTensorIndex) { + self.fbb_.push_slot::(SparseTensor::VT_SPARSEINDEX_TYPE, sparseIndex_type, SparseTensorIndex::NONE); + } + #[inline] + pub fn add_sparseIndex(&mut self, sparseIndex: flatbuffers::WIPOffset) { + self.fbb_.push_slot_always::>(SparseTensor::VT_SPARSEINDEX, sparseIndex); + } + #[inline] + pub fn add_data(&mut self, data: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>(SparseTensor::VT_DATA, data); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, SparseTensor::VT_TYPE_,"type_"); + self.fbb_.required(o, SparseTensor::VT_SHAPE,"shape"); + self.fbb_.required(o, SparseTensor::VT_SPARSEINDEX,"sparseIndex"); + self.fbb_.required(o, SparseTensor::VT_DATA,"data"); + flatbuffers::WIPOffset::new(o.value()) + } } -impl std::fmt::Debug for SparseTensor<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut ds = f.debug_struct("SparseTensor"); - ds.field("type_type", &self.type_type()); - match self.type_type() { - Type::Null => { - if let Some(x) = self.type_as_null() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Int => { - if let Some(x) = self.type_as_int() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::FloatingPoint => { - if let Some(x) = self.type_as_floating_point() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Binary => { - if let Some(x) = self.type_as_binary() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Utf8 => { - if let Some(x) = self.type_as_utf_8() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Bool => { - if let Some(x) = self.type_as_bool() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Decimal => { - if let Some(x) = self.type_as_decimal() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Date => { - if let Some(x) = self.type_as_date() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Time => { - if let Some(x) = self.type_as_time() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Timestamp => { - if let Some(x) = self.type_as_timestamp() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Interval => { - if let Some(x) = self.type_as_interval() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::List => { - if let Some(x) = self.type_as_list() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Struct_ => { - if let Some(x) = self.type_as_struct_() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Union => { - if let Some(x) = self.type_as_union() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::FixedSizeBinary => { - if let Some(x) = self.type_as_fixed_size_binary() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::FixedSizeList => { - if let Some(x) = self.type_as_fixed_size_list() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Map => { - if let Some(x) = self.type_as_map() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::Duration => { - if let Some(x) = self.type_as_duration() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::LargeBinary => { - if let Some(x) = self.type_as_large_binary() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::LargeUtf8 => { - if let Some(x) = self.type_as_large_utf_8() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - Type::LargeList => { - if let Some(x) = self.type_as_large_list() { - ds.field("type_", &x) - } else { - ds.field( - "type_", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - _ => { - let x: Option<()> = None; - ds.field("type_", &x) - } - }; - ds.field("shape", &self.shape()); - ds.field("non_zero_length", &self.non_zero_length()); - ds.field("sparseIndex_type", &self.sparseIndex_type()); - match self.sparseIndex_type() { - SparseTensorIndex::SparseTensorIndexCOO => { - if let Some(x) = self.sparseIndex_as_sparse_tensor_index_coo() { - ds.field("sparseIndex", &x) - } else { - ds.field( - "sparseIndex", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - SparseTensorIndex::SparseMatrixIndexCSX => { - if let Some(x) = self.sparseIndex_as_sparse_matrix_index_csx() { - ds.field("sparseIndex", &x) - } else { - ds.field( - "sparseIndex", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - SparseTensorIndex::SparseTensorIndexCSF => { - if let Some(x) = self.sparseIndex_as_sparse_tensor_index_csf() { - ds.field("sparseIndex", &x) - } else { - ds.field( - "sparseIndex", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) - } - } - _ => { - let x: Option<()> = None; - ds.field("sparseIndex", &x) - } - }; - ds.field("data", &self.data()); - ds.finish() - } +impl core::fmt::Debug for SparseTensor<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensor"); + ds.field("type_type", &self.type_type()); + match self.type_type() { + Type::Null => { + if let Some(x) = self.type_as_null() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Int => { + if let Some(x) = self.type_as_int() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::FloatingPoint => { + if let Some(x) = self.type_as_floating_point() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Binary => { + if let Some(x) = self.type_as_binary() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Utf8 => { + if let Some(x) = self.type_as_utf_8() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Bool => { + if let Some(x) = self.type_as_bool() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Decimal => { + if let Some(x) = self.type_as_decimal() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Date => { + if let Some(x) = self.type_as_date() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Time => { + if let Some(x) = self.type_as_time() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Timestamp => { + if let Some(x) = self.type_as_timestamp() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Interval => { + if let Some(x) = self.type_as_interval() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::List => { + if let Some(x) = self.type_as_list() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Struct_ => { + if let Some(x) = self.type_as_struct_() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Union => { + if let Some(x) = self.type_as_union() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::FixedSizeBinary => { + if let Some(x) = self.type_as_fixed_size_binary() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::FixedSizeList => { + if let Some(x) = self.type_as_fixed_size_list() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Map => { + if let Some(x) = self.type_as_map() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::Duration => { + if let Some(x) = self.type_as_duration() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::LargeBinary => { + if let Some(x) = self.type_as_large_binary() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::LargeUtf8 => { + if let Some(x) = self.type_as_large_utf_8() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Type::LargeList => { + if let Some(x) = self.type_as_large_list() { + ds.field("type_", &x) + } else { + ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + _ => { + let x: Option<()> = None; + ds.field("type_", &x) + }, + }; + ds.field("shape", &self.shape()); + ds.field("non_zero_length", &self.non_zero_length()); + ds.field("sparseIndex_type", &self.sparseIndex_type()); + match self.sparseIndex_type() { + SparseTensorIndex::SparseTensorIndexCOO => { + if let Some(x) = self.sparseIndex_as_sparse_tensor_index_coo() { + ds.field("sparseIndex", &x) + } else { + ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + SparseTensorIndex::SparseMatrixIndexCSX => { + if let Some(x) = self.sparseIndex_as_sparse_matrix_index_csx() { + ds.field("sparseIndex", &x) + } else { + ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + SparseTensorIndex::SparseTensorIndexCSF => { + if let Some(x) = self.sparseIndex_as_sparse_tensor_index_csf() { + ds.field("sparseIndex", &x) + } else { + ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + _ => { + let x: Option<()> = None; + ds.field("sparseIndex", &x) + }, + }; + ds.field("data", &self.data()); + ds.finish() + } } -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_root_as_sparse_tensor<'a>(buf: &'a [u8]) -> SparseTensor<'a> { - unsafe { flatbuffers::root_unchecked::>(buf) } -} - -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_size_prefixed_root_as_sparse_tensor<'a>(buf: &'a [u8]) -> SparseTensor<'a> { - unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } -} - #[inline] /// Verifies that a buffer of bytes contains a `SparseTensor` /// and returns it. @@ -1828,10 +1595,8 @@ pub fn get_size_prefixed_root_as_sparse_tensor<'a>(buf: &'a [u8]) -> SparseTenso /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_sparse_tensor_unchecked`. -pub fn root_as_sparse_tensor( - buf: &[u8], -) -> Result { - flatbuffers::root::(buf) +pub fn root_as_sparse_tensor(buf: &[u8]) -> Result { + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -1840,10 +1605,8 @@ pub fn root_as_sparse_tensor( /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_sparse_tensor_unchecked`. -pub fn size_prefixed_root_as_sparse_tensor( - buf: &[u8], -) -> Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_sparse_tensor(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -1853,10 +1616,10 @@ pub fn size_prefixed_root_as_sparse_tensor( /// previous, unchecked, behavior use /// `root_as_sparse_tensor_unchecked`. pub fn root_as_sparse_tensor_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -1866,37 +1629,33 @@ pub fn root_as_sparse_tensor_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_sparse_tensor_unchecked`. pub fn size_prefixed_root_as_sparse_tensor_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a SparseTensor and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `SparseTensor`. pub unsafe fn root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed SparseTensor and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `SparseTensor`. pub unsafe fn size_prefixed_root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_sparse_tensor_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_sparse_tensor_buffer<'a, 'b>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>, -) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_sparse_tensor_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); } diff --git a/arrow/src/ipc/gen/Tensor.rs b/arrow/src/ipc/gen/Tensor.rs index 120636eaf1f..f22ff23c98b 100644 --- a/arrow/src/ipc/gen/Tensor.rs +++ b/arrow/src/ipc/gen/Tensor.rs @@ -36,16 +36,19 @@ pub struct TensorDim<'a> { impl<'a> flatbuffers::Follow<'a> for TensorDim<'a> { type Inner = TensorDim<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> TensorDim<'a> { + pub const VT_SIZE_: flatbuffers::VOffsetT = 4; + pub const VT_NAME: flatbuffers::VOffsetT = 6; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { TensorDim { _tab: table } } #[allow(unused_mut)] @@ -61,19 +64,24 @@ impl<'a> TensorDim<'a> { builder.finish() } - pub const VT_SIZE_: flatbuffers::VOffsetT = 4; - pub const VT_NAME: flatbuffers::VOffsetT = 6; - /// Length of dimension #[inline] pub fn size_(&self) -> i64 { - self._tab.get::(TensorDim::VT_SIZE_, Some(0)).unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(TensorDim::VT_SIZE_, Some(0)).unwrap() } } /// Name of the dimension, optional #[inline] pub fn name(&self) -> Option<&'a str> { - self._tab - .get::>(TensorDim::VT_NAME, None) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(TensorDim::VT_NAME, None) + } } } @@ -85,9 +93,9 @@ impl flatbuffers::Verifiable for TensorDim<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_field::(&"size_", Self::VT_SIZE_, false)? + .visit_field::("size_", Self::VT_SIZE_, false)? .visit_field::>( - &"name", + "name", Self::VT_NAME, false, )? @@ -108,6 +116,7 @@ impl<'a> Default for TensorDimArgs<'a> { } } } + pub struct TensorDimBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -139,8 +148,8 @@ impl<'a: 'b, 'b> TensorDimBuilder<'a, 'b> { } } -impl std::fmt::Debug for TensorDim<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for TensorDim<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("TensorDim"); ds.field("size_", &self.size_()); ds.field("name", &self.name()); @@ -157,16 +166,22 @@ pub struct Tensor<'a> { impl<'a> flatbuffers::Follow<'a> for Tensor<'a> { type Inner = Tensor<'a>; #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { - _tab: flatbuffers::Table { buf, loc }, + _tab: flatbuffers::Table::new(buf, loc), } } } impl<'a> Tensor<'a> { + pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_TYPE_: flatbuffers::VOffsetT = 6; + pub const VT_SHAPE: flatbuffers::VOffsetT = 8; + pub const VT_STRIDES: flatbuffers::VOffsetT = 10; + pub const VT_DATA: flatbuffers::VOffsetT = 12; + #[inline] - pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { Tensor { _tab: table } } #[allow(unused_mut)] @@ -191,61 +206,81 @@ impl<'a> Tensor<'a> { builder.finish() } - pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_TYPE_: flatbuffers::VOffsetT = 6; - pub const VT_SHAPE: flatbuffers::VOffsetT = 8; - pub const VT_STRIDES: flatbuffers::VOffsetT = 10; - pub const VT_DATA: flatbuffers::VOffsetT = 12; - #[inline] pub fn type_type(&self) -> Type { - self._tab - .get::(Tensor::VT_TYPE_TYPE, Some(Type::NONE)) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Tensor::VT_TYPE_TYPE, Some(Type::NONE)) + .unwrap() + } } /// The type of data contained in a value cell. Currently only fixed-width /// value types are supported, no strings or nested types #[inline] pub fn type_(&self) -> flatbuffers::Table<'a> { - self._tab - .get::>>( - Tensor::VT_TYPE_, - None, - ) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Tensor::VT_TYPE_, + None, + ) + .unwrap() + } } /// The dimensions of the tensor, optionally named #[inline] pub fn shape( &self, ) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>> { - self._tab - .get::>, - >>(Tensor::VT_SHAPE, None) - .unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>, + >>(Tensor::VT_SHAPE, None) + .unwrap() + } } /// Non-negative byte offsets to advance one value cell along each dimension /// If omitted, default to row-major order (C-like). #[inline] pub fn strides(&self) -> Option> { - self._tab - .get::>>( - Tensor::VT_STRIDES, - None, - ) + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Tensor::VT_STRIDES, + None, + ) + } } /// The location and size of the tensor's data #[inline] pub fn data(&self) -> &'a Buffer { - self._tab.get::(Tensor::VT_DATA, None).unwrap() + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Tensor::VT_DATA, None).unwrap() } } #[inline] #[allow(non_snake_case)] pub fn type_as_null(&self) -> Option> { if self.type_type() == Type::Null { let u = self.type_(); - Some(Null::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Null::init_from_table(u) }) } else { None } @@ -256,7 +291,10 @@ impl<'a> Tensor<'a> { pub fn type_as_int(&self) -> Option> { if self.type_type() == Type::Int { let u = self.type_(); - Some(Int::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Int::init_from_table(u) }) } else { None } @@ -267,7 +305,10 @@ impl<'a> Tensor<'a> { pub fn type_as_floating_point(&self) -> Option> { if self.type_type() == Type::FloatingPoint { let u = self.type_(); - Some(FloatingPoint::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FloatingPoint::init_from_table(u) }) } else { None } @@ -278,7 +319,10 @@ impl<'a> Tensor<'a> { pub fn type_as_binary(&self) -> Option> { if self.type_type() == Type::Binary { let u = self.type_(); - Some(Binary::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Binary::init_from_table(u) }) } else { None } @@ -289,7 +333,10 @@ impl<'a> Tensor<'a> { pub fn type_as_utf_8(&self) -> Option> { if self.type_type() == Type::Utf8 { let u = self.type_(); - Some(Utf8::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Utf8::init_from_table(u) }) } else { None } @@ -300,7 +347,10 @@ impl<'a> Tensor<'a> { pub fn type_as_bool(&self) -> Option> { if self.type_type() == Type::Bool { let u = self.type_(); - Some(Bool::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Bool::init_from_table(u) }) } else { None } @@ -311,7 +361,10 @@ impl<'a> Tensor<'a> { pub fn type_as_decimal(&self) -> Option> { if self.type_type() == Type::Decimal { let u = self.type_(); - Some(Decimal::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Decimal::init_from_table(u) }) } else { None } @@ -322,7 +375,10 @@ impl<'a> Tensor<'a> { pub fn type_as_date(&self) -> Option> { if self.type_type() == Type::Date { let u = self.type_(); - Some(Date::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Date::init_from_table(u) }) } else { None } @@ -333,7 +389,10 @@ impl<'a> Tensor<'a> { pub fn type_as_time(&self) -> Option> { if self.type_type() == Type::Time { let u = self.type_(); - Some(Time::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Time::init_from_table(u) }) } else { None } @@ -344,7 +403,10 @@ impl<'a> Tensor<'a> { pub fn type_as_timestamp(&self) -> Option> { if self.type_type() == Type::Timestamp { let u = self.type_(); - Some(Timestamp::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Timestamp::init_from_table(u) }) } else { None } @@ -355,7 +417,10 @@ impl<'a> Tensor<'a> { pub fn type_as_interval(&self) -> Option> { if self.type_type() == Type::Interval { let u = self.type_(); - Some(Interval::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Interval::init_from_table(u) }) } else { None } @@ -366,7 +431,10 @@ impl<'a> Tensor<'a> { pub fn type_as_list(&self) -> Option> { if self.type_type() == Type::List { let u = self.type_(); - Some(List::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { List::init_from_table(u) }) } else { None } @@ -377,7 +445,10 @@ impl<'a> Tensor<'a> { pub fn type_as_struct_(&self) -> Option> { if self.type_type() == Type::Struct_ { let u = self.type_(); - Some(Struct_::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Struct_::init_from_table(u) }) } else { None } @@ -388,7 +459,10 @@ impl<'a> Tensor<'a> { pub fn type_as_union(&self) -> Option> { if self.type_type() == Type::Union { let u = self.type_(); - Some(Union::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Union::init_from_table(u) }) } else { None } @@ -399,7 +473,10 @@ impl<'a> Tensor<'a> { pub fn type_as_fixed_size_binary(&self) -> Option> { if self.type_type() == Type::FixedSizeBinary { let u = self.type_(); - Some(FixedSizeBinary::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeBinary::init_from_table(u) }) } else { None } @@ -410,7 +487,10 @@ impl<'a> Tensor<'a> { pub fn type_as_fixed_size_list(&self) -> Option> { if self.type_type() == Type::FixedSizeList { let u = self.type_(); - Some(FixedSizeList::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeList::init_from_table(u) }) } else { None } @@ -421,7 +501,10 @@ impl<'a> Tensor<'a> { pub fn type_as_map(&self) -> Option> { if self.type_type() == Type::Map { let u = self.type_(); - Some(Map::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Map::init_from_table(u) }) } else { None } @@ -432,7 +515,10 @@ impl<'a> Tensor<'a> { pub fn type_as_duration(&self) -> Option> { if self.type_type() == Type::Duration { let u = self.type_(); - Some(Duration::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Duration::init_from_table(u) }) } else { None } @@ -443,7 +529,10 @@ impl<'a> Tensor<'a> { pub fn type_as_large_binary(&self) -> Option> { if self.type_type() == Type::LargeBinary { let u = self.type_(); - Some(LargeBinary::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeBinary::init_from_table(u) }) } else { None } @@ -454,7 +543,10 @@ impl<'a> Tensor<'a> { pub fn type_as_large_utf_8(&self) -> Option> { if self.type_type() == Type::LargeUtf8 { let u = self.type_(); - Some(LargeUtf8::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeUtf8::init_from_table(u) }) } else { None } @@ -465,7 +557,10 @@ impl<'a> Tensor<'a> { pub fn type_as_large_list(&self) -> Option> { if self.type_type() == Type::LargeList { let u = self.type_(); - Some(LargeList::init_from_table(u)) + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeList::init_from_table(u) }) } else { None } @@ -480,7 +575,7 @@ impl flatbuffers::Verifiable for Tensor<'_> { ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use flatbuffers::Verifiable; v.visit_table(pos)? - .visit_union::(&"type_type", Self::VT_TYPE_TYPE, &"type_", Self::VT_TYPE_, true, |key, v, pos| { + .visit_union::("type_type", Self::VT_TYPE_TYPE, "type_", Self::VT_TYPE_, true, |key, v, pos| { match key { Type::Null => v.verify_union_variant::>("Type::Null", pos), Type::Int => v.verify_union_variant::>("Type::Int", pos), @@ -506,9 +601,9 @@ impl flatbuffers::Verifiable for Tensor<'_> { _ => Ok(()), } })? - .visit_field::>>>(&"shape", Self::VT_SHAPE, true)? - .visit_field::>>(&"strides", Self::VT_STRIDES, false)? - .visit_field::(&"data", Self::VT_DATA, true)? + .visit_field::>>>("shape", Self::VT_SHAPE, true)? + .visit_field::>>("strides", Self::VT_STRIDES, false)? + .visit_field::("data", Self::VT_DATA, true)? .finish(); Ok(()) } @@ -536,6 +631,7 @@ impl<'a> Default for TensorArgs<'a> { } } } + pub struct TensorBuilder<'a: 'b, 'b> { fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, start_: flatbuffers::WIPOffset, @@ -596,8 +692,8 @@ impl<'a: 'b, 'b> TensorBuilder<'a, 'b> { } } -impl std::fmt::Debug for Tensor<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Debug for Tensor<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let mut ds = f.debug_struct("Tensor"); ds.field("type_type", &self.type_type()); match self.type_type() { @@ -822,18 +918,6 @@ impl std::fmt::Debug for Tensor<'_> { ds.finish() } } -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_root_as_tensor<'a>(buf: &'a [u8]) -> Tensor<'a> { - unsafe { flatbuffers::root_unchecked::>(buf) } -} - -#[inline] -#[deprecated(since = "2.0.0", note = "Deprecated in favor of `root_as...` methods.")] -pub fn get_size_prefixed_root_as_tensor<'a>(buf: &'a [u8]) -> Tensor<'a> { - unsafe { flatbuffers::size_prefixed_root_unchecked::>(buf) } -} - #[inline] /// Verifies that a buffer of bytes contains a `Tensor` /// and returns it. diff --git a/arrow/src/ipc/reader.rs b/arrow/src/ipc/reader.rs index cc45b22373d..1f2824b343a 100644 --- a/arrow/src/ipc/reader.rs +++ b/arrow/src/ipc/reader.rs @@ -72,10 +72,10 @@ fn read_buffer( /// - cast the 64-bit array to the appropriate data type #[allow(clippy::too_many_arguments)] fn create_array( - nodes: &[ipc::FieldNode], + nodes: flatbuffers::Vector<'_, ipc::FieldNode>, field: &Field, data: &Buffer, - buffers: &[ipc::Buffer], + buffers: flatbuffers::Vector<'_, ipc::Buffer>, dictionaries_by_id: &HashMap, mut node_index: usize, mut buffer_index: usize, @@ -86,12 +86,13 @@ fn create_array( let array = match data_type { Utf8 | Binary | LargeBinary | LargeUtf8 => { let array = create_primitive_array( - &nodes[node_index], + nodes.get(node_index), data_type, - &buffers[buffer_index..buffer_index + 3] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>>()?, + &[ + read_buffer(buffers.get(buffer_index), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 2), data, compression_codec)?, + ], ); node_index += 1; buffer_index += 3; @@ -99,23 +100,23 @@ fn create_array( } FixedSizeBinary(_) => { let array = create_primitive_array( - &nodes[node_index], + nodes.get(node_index), data_type, - &buffers[buffer_index..buffer_index + 2] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>>()?, + &[ + read_buffer(buffers.get(buffer_index), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?, + ], ); node_index += 1; buffer_index += 2; array } List(ref list_field) | LargeList(ref list_field) | Map(ref list_field, _) => { - let list_node = &nodes[node_index]; - let list_buffers: Vec = buffers[buffer_index..buffer_index + 2] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>()?; + let list_node = nodes.get(node_index); + let list_buffers = [ + read_buffer(buffers.get(buffer_index), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?, + ]; node_index += 1; buffer_index += 2; let triple = create_array( @@ -132,14 +133,15 @@ fn create_array( node_index = triple.1; buffer_index = triple.2; - create_list_array(list_node, data_type, &list_buffers[..], triple.0) + create_list_array(list_node, data_type, &list_buffers, triple.0) } FixedSizeList(ref list_field, _) => { - let list_node = &nodes[node_index]; - let list_buffers: Vec = buffers[buffer_index..=buffer_index] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>()?; + let list_node = nodes.get(node_index); + let list_buffers = [read_buffer( + buffers.get(buffer_index), + data, + compression_codec, + )?]; node_index += 1; buffer_index += 1; let triple = create_array( @@ -156,12 +158,12 @@ fn create_array( node_index = triple.1; buffer_index = triple.2; - create_list_array(list_node, data_type, &list_buffers[..], triple.0) + create_list_array(list_node, data_type, &list_buffers, triple.0) } Struct(struct_fields) => { - let struct_node = &nodes[node_index]; - let null_buffer: Buffer = - read_buffer(&buffers[buffer_index], data, compression_codec)?; + let struct_node = nodes.get(node_index); + let null_buffer = + read_buffer(buffers.get(buffer_index), data, compression_codec)?; node_index += 1; buffer_index += 1; @@ -196,11 +198,11 @@ fn create_array( } // Create dictionary array from RecordBatch Dictionary(_, _) => { - let index_node = &nodes[node_index]; - let index_buffers: Vec = buffers[buffer_index..buffer_index + 2] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>()?; + let index_node = nodes.get(node_index); + let index_buffers = [ + read_buffer(buffers.get(buffer_index), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?, + ]; let dict_id = field.dict_id().ok_or_else(|| { ArrowError::IoError(format!("Field {} does not have dict id", field)) @@ -218,12 +220,12 @@ fn create_array( create_dictionary_array( index_node, data_type, - &index_buffers[..], + &index_buffers, value_array.clone(), ) } Union(fields, field_type_ids, mode) => { - let union_node = nodes[node_index]; + let union_node = nodes.get(node_index); node_index += 1; let len = union_node.length() as usize; @@ -231,12 +233,12 @@ fn create_array( // In V4, union types has validity bitmap // In V5 and later, union types have no validity bitmap if metadata < &ipc::MetadataVersion::V5 { - read_buffer(&buffers[buffer_index], data, compression_codec)?; + read_buffer(buffers.get(buffer_index), data, compression_codec)?; buffer_index += 1; } let type_ids: Buffer = - read_buffer(&buffers[buffer_index], data, compression_codec)?[..len] + read_buffer(buffers.get(buffer_index), data, compression_codec)?[..len] .into(); buffer_index += 1; @@ -244,7 +246,7 @@ fn create_array( let value_offsets = match mode { UnionMode::Dense => { let buffer = - read_buffer(&buffers[buffer_index], data, compression_codec)?; + read_buffer(buffers.get(buffer_index), data, compression_codec)?; buffer_index += 1; Some(buffer[..len * 4].into()) } @@ -277,8 +279,9 @@ fn create_array( Arc::new(array) } Null => { - let length = nodes[node_index].length(); - let null_count = nodes[node_index].null_count(); + let node = nodes.get(node_index); + let length = node.length(); + let null_count = node.null_count(); if length != null_count { return Err(ArrowError::IoError(format!( @@ -298,12 +301,12 @@ fn create_array( } _ => { let array = create_primitive_array( - &nodes[node_index], + nodes.get(node_index), data_type, - &buffers[buffer_index..buffer_index + 2] - .iter() - .map(|buf| read_buffer(buf, data, compression_codec)) - .collect::>>()?, + &[ + read_buffer(buffers.get(buffer_index), data, compression_codec)?, + read_buffer(buffers.get(buffer_index + 1), data, compression_codec)?, + ], ); node_index += 1; buffer_index += 2; @@ -875,7 +878,7 @@ impl FileReader { Ok(Self { reader, schema: Arc::new(schema), - blocks: blocks.to_vec(), + blocks: blocks.iter().copied().collect(), current_block: 0, total_blocks, dictionaries_by_id, From f85001f12a6ef71b21cb525f8e1288c771a39359 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Wed, 19 Oct 2022 15:55:34 +1300 Subject: [PATCH 2/2] Format --- arrow/src/ipc/gen/SparseTensor.rs | 3041 ++++++++++++++++------------- 1 file changed, 1726 insertions(+), 1315 deletions(-) diff --git a/arrow/src/ipc/gen/SparseTensor.rs b/arrow/src/ipc/gen/SparseTensor.rs index 55d769bf3b1..317831c59ef 100644 --- a/arrow/src/ipc/gen/SparseTensor.rs +++ b/arrow/src/ipc/gen/SparseTensor.rs @@ -24,15 +24,24 @@ use flatbuffers::EndianScalar; use std::{cmp::Ordering, mem}; // automatically generated by the FlatBuffers compiler, do not modify -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] pub const ENUM_MIN_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] pub const ENUM_MAX_SPARSE_MATRIX_COMPRESSED_AXIS: i16 = 1; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] #[allow(non_camel_case_types)] pub const ENUM_VALUES_SPARSE_MATRIX_COMPRESSED_AXIS: [SparseMatrixCompressedAxis; 2] = [ - SparseMatrixCompressedAxis::Row, - SparseMatrixCompressedAxis::Column, + SparseMatrixCompressedAxis::Row, + SparseMatrixCompressedAxis::Column, ]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] @@ -40,40 +49,37 @@ pub const ENUM_VALUES_SPARSE_MATRIX_COMPRESSED_AXIS: [SparseMatrixCompressedAxis pub struct SparseMatrixCompressedAxis(pub i16); #[allow(non_upper_case_globals)] impl SparseMatrixCompressedAxis { - pub const Row: Self = Self(0); - pub const Column: Self = Self(1); - - pub const ENUM_MIN: i16 = 0; - pub const ENUM_MAX: i16 = 1; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::Row, - Self::Column, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::Row => Some("Row"), - Self::Column => Some("Column"), - _ => None, - } - } + pub const Row: Self = Self(0); + pub const Column: Self = Self(1); + + pub const ENUM_MIN: i16 = 0; + pub const ENUM_MAX: i16 = 1; + pub const ENUM_VALUES: &'static [Self] = &[Self::Row, Self::Column]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Row => Some("Row"), + Self::Column => Some("Column"), + _ => None, + } + } } impl core::fmt::Debug for SparseMatrixCompressedAxis { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } } - } } impl<'a> flatbuffers::Follow<'a> for SparseMatrixCompressedAxis { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for SparseMatrixCompressedAxis { @@ -85,41 +91,51 @@ impl flatbuffers::Push for SparseMatrixCompressedAxis { } impl flatbuffers::EndianScalar for SparseMatrixCompressedAxis { - type Scalar = i16; - #[inline] - fn to_little_endian(self) -> i16 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i16) -> Self { - let b = i16::from_le(v); - Self(b) - } + type Scalar = i16; + #[inline] + fn to_little_endian(self) -> i16 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for SparseMatrixCompressedAxis { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - i16::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + i16::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for SparseMatrixCompressedAxis {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] pub const ENUM_MIN_SPARSE_TENSOR_INDEX: u8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] pub const ENUM_MAX_SPARSE_TENSOR_INDEX: u8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." +)] #[allow(non_camel_case_types)] pub const ENUM_VALUES_SPARSE_TENSOR_INDEX: [SparseTensorIndex; 4] = [ - SparseTensorIndex::NONE, - SparseTensorIndex::SparseTensorIndexCOO, - SparseTensorIndex::SparseMatrixIndexCSX, - SparseTensorIndex::SparseTensorIndexCSF, + SparseTensorIndex::NONE, + SparseTensorIndex::SparseTensorIndexCOO, + SparseTensorIndex::SparseMatrixIndexCSX, + SparseTensorIndex::SparseTensorIndexCSF, ]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] @@ -127,46 +143,46 @@ pub const ENUM_VALUES_SPARSE_TENSOR_INDEX: [SparseTensorIndex; 4] = [ pub struct SparseTensorIndex(pub u8); #[allow(non_upper_case_globals)] impl SparseTensorIndex { - pub const NONE: Self = Self(0); - pub const SparseTensorIndexCOO: Self = Self(1); - pub const SparseMatrixIndexCSX: Self = Self(2); - pub const SparseTensorIndexCSF: Self = Self(3); - - pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::NONE, - Self::SparseTensorIndexCOO, - Self::SparseMatrixIndexCSX, - Self::SparseTensorIndexCSF, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::NONE => Some("NONE"), - Self::SparseTensorIndexCOO => Some("SparseTensorIndexCOO"), - Self::SparseMatrixIndexCSX => Some("SparseMatrixIndexCSX"), - Self::SparseTensorIndexCSF => Some("SparseTensorIndexCSF"), - _ => None, - } - } + pub const NONE: Self = Self(0); + pub const SparseTensorIndexCOO: Self = Self(1); + pub const SparseMatrixIndexCSX: Self = Self(2); + pub const SparseTensorIndexCSF: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::SparseTensorIndexCOO, + Self::SparseMatrixIndexCSX, + Self::SparseTensorIndexCSF, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::SparseTensorIndexCOO => Some("SparseTensorIndexCOO"), + Self::SparseMatrixIndexCSX => Some("SparseMatrixIndexCSX"), + Self::SparseTensorIndexCSF => Some("SparseTensorIndexCSF"), + _ => None, + } + } } impl core::fmt::Debug for SparseTensorIndex { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } } - } } impl<'a> flatbuffers::Follow<'a> for SparseTensorIndex { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } } impl flatbuffers::Push for SparseTensorIndex { @@ -178,27 +194,28 @@ impl flatbuffers::Push for SparseTensorIndex { } impl flatbuffers::EndianScalar for SparseTensorIndex { - type Scalar = u8; - #[inline] - fn to_little_endian(self) -> u8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: u8) -> Self { - let b = u8::from_le(v); - Self(b) - } + type Scalar = u8; + #[inline] + fn to_little_endian(self) -> u8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); + Self(b) + } } impl<'a> flatbuffers::Verifiable for SparseTensorIndex { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - u8::run_verifier(v, pos) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + u8::run_verifier(v, pos) + } } impl flatbuffers::SimpleToVerifyInSlice for SparseTensorIndex {} @@ -240,94 +257,131 @@ pub enum SparseTensorIndexCOOOffset {} /// (row-major order), and it does not have duplicated entries. Otherwise, /// the indices may not be sorted, or may have duplicated entries. pub struct SparseTensorIndexCOO<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCOO<'a> { - type Inner = SparseTensorIndexCOO<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } + type Inner = SparseTensorIndexCOO<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } } impl<'a> SparseTensorIndexCOO<'a> { - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 4; - pub const VT_INDICESSTRIDES: flatbuffers::VOffsetT = 6; - pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 8; - pub const VT_ISCANONICAL: flatbuffers::VOffsetT = 10; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensorIndexCOO { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorIndexCOOArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorIndexCOOBuilder::new(_fbb); - if let Some(x) = args.indicesBuffer { builder.add_indicesBuffer(x); } - if let Some(x) = args.indicesStrides { builder.add_indicesStrides(x); } - if let Some(x) = args.indicesType { builder.add_indicesType(x); } - builder.add_isCanonical(args.isCanonical); - builder.finish() - } - - - /// The type of values in indicesBuffer - #[inline] - pub fn indicesType(&self) -> Int<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(SparseTensorIndexCOO::VT_INDICESTYPE, None).unwrap()} - } - /// Non-negative byte offsets to advance one value cell along each dimension - /// If omitted, default to row-major order (C-like). - #[inline] - pub fn indicesStrides(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensorIndexCOO::VT_INDICESSTRIDES, None)} - } - /// The location and size of the indices matrix's data - #[inline] - pub fn indicesBuffer(&self) -> &'a Buffer { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensorIndexCOO::VT_INDICESBUFFER, None).unwrap()} - } - /// This flag is true if and only if the indices matrix is sorted in - /// row-major order, and does not have duplicated entries. - /// This sort order is the same as of Tensorflow's SparseTensor, - /// but it is inverse order of SciPy's canonical coo_matrix - /// (SciPy employs column-major order for its coo_matrix). - #[inline] - pub fn isCanonical(&self) -> bool { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensorIndexCOO::VT_ISCANONICAL, Some(false)).unwrap()} - } + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 4; + pub const VT_INDICESSTRIDES: flatbuffers::VOffsetT = 6; + pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 8; + pub const VT_ISCANONICAL: flatbuffers::VOffsetT = 10; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensorIndexCOO { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorIndexCOOArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorIndexCOOBuilder::new(_fbb); + if let Some(x) = args.indicesBuffer { + builder.add_indicesBuffer(x); + } + if let Some(x) = args.indicesStrides { + builder.add_indicesStrides(x); + } + if let Some(x) = args.indicesType { + builder.add_indicesType(x); + } + builder.add_isCanonical(args.isCanonical); + builder.finish() + } + + /// The type of values in indicesBuffer + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + SparseTensorIndexCOO::VT_INDICESTYPE, + None, + ) + .unwrap() + } + } + /// Non-negative byte offsets to advance one value cell along each dimension + /// If omitted, default to row-major order (C-like). + #[inline] + pub fn indicesStrides(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensorIndexCOO::VT_INDICESSTRIDES, + None, + ) + } + } + /// The location and size of the indices matrix's data + #[inline] + pub fn indicesBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseTensorIndexCOO::VT_INDICESBUFFER, None) + .unwrap() + } + } + /// This flag is true if and only if the indices matrix is sorted in + /// row-major order, and does not have duplicated entries. + /// This sort order is the same as of Tensorflow's SparseTensor, + /// but it is inverse order of SciPy's canonical coo_matrix + /// (SciPy employs column-major order for its coo_matrix). + #[inline] + pub fn isCanonical(&self) -> bool { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseTensorIndexCOO::VT_ISCANONICAL, Some(false)) + .unwrap() + } + } } impl flatbuffers::Verifiable for SparseTensorIndexCOO<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? - .visit_field::>>("indicesStrides", Self::VT_INDICESSTRIDES, false)? - .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? - .visit_field::("isCanonical", Self::VT_ISCANONICAL, false)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>( + "indicesType", + Self::VT_INDICESTYPE, + true, + )? + .visit_field::>>( + "indicesStrides", + Self::VT_INDICESSTRIDES, + false, + )? + .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? + .visit_field::("isCanonical", Self::VT_ISCANONICAL, false)? + .finish(); + Ok(()) + } } pub struct SparseTensorIndexCOOArgs<'a> { pub indicesType: Option>>, @@ -336,194 +390,265 @@ pub struct SparseTensorIndexCOOArgs<'a> { pub isCanonical: bool, } impl<'a> Default for SparseTensorIndexCOOArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorIndexCOOArgs { - indicesType: None, // required field - indicesStrides: None, - indicesBuffer: None, // required field - isCanonical: false, - } - } + #[inline] + fn default() -> Self { + SparseTensorIndexCOOArgs { + indicesType: None, // required field + indicesStrides: None, + indicesBuffer: None, // required field + isCanonical: false, + } + } } pub struct SparseTensorIndexCOOBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorIndexCOOBuilder<'a, 'b> { - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCOO::VT_INDICESTYPE, indicesType); - } - #[inline] - pub fn add_indicesStrides(&mut self, indicesStrides: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCOO::VT_INDICESSTRIDES, indicesStrides); - } - #[inline] - pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>(SparseTensorIndexCOO::VT_INDICESBUFFER, indicesBuffer); - } - #[inline] - pub fn add_isCanonical(&mut self, isCanonical: bool) { - self.fbb_.push_slot::(SparseTensorIndexCOO::VT_ISCANONICAL, isCanonical, false); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorIndexCOOBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorIndexCOOBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_.required(o, SparseTensorIndexCOO::VT_INDICESTYPE,"indicesType"); - self.fbb_.required(o, SparseTensorIndexCOO::VT_INDICESBUFFER,"indicesBuffer"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCOO::VT_INDICESTYPE, + indicesType, + ); + } + #[inline] + pub fn add_indicesStrides( + &mut self, + indicesStrides: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCOO::VT_INDICESSTRIDES, + indicesStrides, + ); + } + #[inline] + pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>( + SparseTensorIndexCOO::VT_INDICESBUFFER, + indicesBuffer, + ); + } + #[inline] + pub fn add_isCanonical(&mut self, isCanonical: bool) { + self.fbb_.push_slot::( + SparseTensorIndexCOO::VT_ISCANONICAL, + isCanonical, + false, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, + ) -> SparseTensorIndexCOOBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorIndexCOOBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_ + .required(o, SparseTensorIndexCOO::VT_INDICESTYPE, "indicesType"); + self.fbb_ + .required(o, SparseTensorIndexCOO::VT_INDICESBUFFER, "indicesBuffer"); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for SparseTensorIndexCOO<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("SparseTensorIndexCOO"); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesStrides", &self.indicesStrides()); - ds.field("indicesBuffer", &self.indicesBuffer()); - ds.field("isCanonical", &self.isCanonical()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensorIndexCOO"); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesStrides", &self.indicesStrides()); + ds.field("indicesBuffer", &self.indicesBuffer()); + ds.field("isCanonical", &self.isCanonical()); + ds.finish() + } } pub enum SparseMatrixIndexCSXOffset {} #[derive(Copy, Clone, PartialEq)] /// Compressed Sparse format, that is matrix-specific. pub struct SparseMatrixIndexCSX<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseMatrixIndexCSX<'a> { - type Inner = SparseMatrixIndexCSX<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } + type Inner = SparseMatrixIndexCSX<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } } impl<'a> SparseMatrixIndexCSX<'a> { - pub const VT_COMPRESSEDAXIS: flatbuffers::VOffsetT = 4; - pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 6; - pub const VT_INDPTRBUFFER: flatbuffers::VOffsetT = 8; - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 10; - pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 12; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseMatrixIndexCSX { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseMatrixIndexCSXArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseMatrixIndexCSXBuilder::new(_fbb); - if let Some(x) = args.indicesBuffer { builder.add_indicesBuffer(x); } - if let Some(x) = args.indicesType { builder.add_indicesType(x); } - if let Some(x) = args.indptrBuffer { builder.add_indptrBuffer(x); } - if let Some(x) = args.indptrType { builder.add_indptrType(x); } - builder.add_compressedAxis(args.compressedAxis); - builder.finish() - } - - - /// Which axis, row or column, is compressed - #[inline] - pub fn compressedAxis(&self) -> SparseMatrixCompressedAxis { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, Some(SparseMatrixCompressedAxis::Row)).unwrap()} - } - /// The type of values in indptrBuffer - #[inline] - pub fn indptrType(&self) -> Int<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(SparseMatrixIndexCSX::VT_INDPTRTYPE, None).unwrap()} - } - /// indptrBuffer stores the location and size of indptr array that - /// represents the range of the rows. - /// The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. - /// The length of this array is 1 + (the number of rows), and the type - /// of index value is long. - /// - /// For example, let X be the following 6x4 matrix: - /// ```text - /// X := [[0, 1, 2, 0], - /// [0, 0, 3, 0], - /// [0, 4, 0, 5], - /// [0, 0, 0, 0], - /// [6, 0, 7, 8], - /// [0, 9, 0, 0]]. - /// ``` - /// The array of non-zero values in X is: - /// ```text - /// values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. - /// ``` - /// And the indptr of X is: - /// ```text - /// indptr(X) = [0, 2, 3, 5, 5, 8, 10]. - /// ``` - #[inline] - pub fn indptrBuffer(&self) -> &'a Buffer { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_INDPTRBUFFER, None).unwrap()} - } - /// The type of values in indicesBuffer - #[inline] - pub fn indicesType(&self) -> Int<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(SparseMatrixIndexCSX::VT_INDICESTYPE, None).unwrap()} - } - /// indicesBuffer stores the location and size of the array that - /// contains the column indices of the corresponding non-zero values. - /// The type of index value is long. - /// - /// For example, the indices of the above X is: - /// ```text - /// indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. - /// ``` - /// Note that the indices are sorted in lexicographical order for each row. - #[inline] - pub fn indicesBuffer(&self) -> &'a Buffer { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseMatrixIndexCSX::VT_INDICESBUFFER, None).unwrap()} - } + pub const VT_COMPRESSEDAXIS: flatbuffers::VOffsetT = 4; + pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 6; + pub const VT_INDPTRBUFFER: flatbuffers::VOffsetT = 8; + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 10; + pub const VT_INDICESBUFFER: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseMatrixIndexCSX { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseMatrixIndexCSXArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseMatrixIndexCSXBuilder::new(_fbb); + if let Some(x) = args.indicesBuffer { + builder.add_indicesBuffer(x); + } + if let Some(x) = args.indicesType { + builder.add_indicesType(x); + } + if let Some(x) = args.indptrBuffer { + builder.add_indptrBuffer(x); + } + if let Some(x) = args.indptrType { + builder.add_indptrType(x); + } + builder.add_compressedAxis(args.compressedAxis); + builder.finish() + } + + /// Which axis, row or column, is compressed + #[inline] + pub fn compressedAxis(&self) -> SparseMatrixCompressedAxis { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, + Some(SparseMatrixCompressedAxis::Row), + ) + .unwrap() + } + } + /// The type of values in indptrBuffer + #[inline] + pub fn indptrType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + SparseMatrixIndexCSX::VT_INDPTRTYPE, + None, + ) + .unwrap() + } + } + /// indptrBuffer stores the location and size of indptr array that + /// represents the range of the rows. + /// The i-th row spans from `indptr[i]` to `indptr[i+1]` in the data. + /// The length of this array is 1 + (the number of rows), and the type + /// of index value is long. + /// + /// For example, let X be the following 6x4 matrix: + /// ```text + /// X := [[0, 1, 2, 0], + /// [0, 0, 3, 0], + /// [0, 4, 0, 5], + /// [0, 0, 0, 0], + /// [6, 0, 7, 8], + /// [0, 9, 0, 0]]. + /// ``` + /// The array of non-zero values in X is: + /// ```text + /// values(X) = [1, 2, 3, 4, 5, 6, 7, 8, 9]. + /// ``` + /// And the indptr of X is: + /// ```text + /// indptr(X) = [0, 2, 3, 5, 5, 8, 10]. + /// ``` + #[inline] + pub fn indptrBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseMatrixIndexCSX::VT_INDPTRBUFFER, None) + .unwrap() + } + } + /// The type of values in indicesBuffer + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + SparseMatrixIndexCSX::VT_INDICESTYPE, + None, + ) + .unwrap() + } + } + /// indicesBuffer stores the location and size of the array that + /// contains the column indices of the corresponding non-zero values. + /// The type of index value is long. + /// + /// For example, the indices of the above X is: + /// ```text + /// indices(X) = [1, 2, 2, 1, 3, 0, 2, 3, 1]. + /// ``` + /// Note that the indices are sorted in lexicographical order for each row. + #[inline] + pub fn indicesBuffer(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseMatrixIndexCSX::VT_INDICESBUFFER, None) + .unwrap() + } + } } impl flatbuffers::Verifiable for SparseMatrixIndexCSX<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("compressedAxis", Self::VT_COMPRESSEDAXIS, false)? - .visit_field::>("indptrType", Self::VT_INDPTRTYPE, true)? - .visit_field::("indptrBuffer", Self::VT_INDPTRBUFFER, true)? - .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? - .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::( + "compressedAxis", + Self::VT_COMPRESSEDAXIS, + false, + )? + .visit_field::>( + "indptrType", + Self::VT_INDPTRTYPE, + true, + )? + .visit_field::("indptrBuffer", Self::VT_INDPTRBUFFER, true)? + .visit_field::>( + "indicesType", + Self::VT_INDICESTYPE, + true, + )? + .visit_field::("indicesBuffer", Self::VT_INDICESBUFFER, true)? + .finish(); + Ok(()) + } } pub struct SparseMatrixIndexCSXArgs<'a> { pub compressedAxis: SparseMatrixCompressedAxis, @@ -533,230 +658,319 @@ pub struct SparseMatrixIndexCSXArgs<'a> { pub indicesBuffer: Option<&'a Buffer>, } impl<'a> Default for SparseMatrixIndexCSXArgs<'a> { - #[inline] - fn default() -> Self { - SparseMatrixIndexCSXArgs { - compressedAxis: SparseMatrixCompressedAxis::Row, - indptrType: None, // required field - indptrBuffer: None, // required field - indicesType: None, // required field - indicesBuffer: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseMatrixIndexCSXArgs { + compressedAxis: SparseMatrixCompressedAxis::Row, + indptrType: None, // required field + indptrBuffer: None, // required field + indicesType: None, // required field + indicesBuffer: None, // required field + } + } } pub struct SparseMatrixIndexCSXBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseMatrixIndexCSXBuilder<'a, 'b> { - #[inline] - pub fn add_compressedAxis(&mut self, compressedAxis: SparseMatrixCompressedAxis) { - self.fbb_.push_slot::(SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, compressedAxis, SparseMatrixCompressedAxis::Row); - } - #[inline] - pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseMatrixIndexCSX::VT_INDPTRTYPE, indptrType); - } - #[inline] - pub fn add_indptrBuffer(&mut self, indptrBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDPTRBUFFER, indptrBuffer); - } - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseMatrixIndexCSX::VT_INDICESTYPE, indicesType); - } - #[inline] - pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>(SparseMatrixIndexCSX::VT_INDICESBUFFER, indicesBuffer); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseMatrixIndexCSXBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseMatrixIndexCSXBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDPTRTYPE,"indptrType"); - self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDPTRBUFFER,"indptrBuffer"); - self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDICESTYPE,"indicesType"); - self.fbb_.required(o, SparseMatrixIndexCSX::VT_INDICESBUFFER,"indicesBuffer"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_compressedAxis(&mut self, compressedAxis: SparseMatrixCompressedAxis) { + self.fbb_.push_slot::( + SparseMatrixIndexCSX::VT_COMPRESSEDAXIS, + compressedAxis, + SparseMatrixCompressedAxis::Row, + ); + } + #[inline] + pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>( + SparseMatrixIndexCSX::VT_INDPTRTYPE, + indptrType, + ); + } + #[inline] + pub fn add_indptrBuffer(&mut self, indptrBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>( + SparseMatrixIndexCSX::VT_INDPTRBUFFER, + indptrBuffer, + ); + } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>( + SparseMatrixIndexCSX::VT_INDICESTYPE, + indicesType, + ); + } + #[inline] + pub fn add_indicesBuffer(&mut self, indicesBuffer: &Buffer) { + self.fbb_.push_slot_always::<&Buffer>( + SparseMatrixIndexCSX::VT_INDICESBUFFER, + indicesBuffer, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, + ) -> SparseMatrixIndexCSXBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseMatrixIndexCSXBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_ + .required(o, SparseMatrixIndexCSX::VT_INDPTRTYPE, "indptrType"); + self.fbb_ + .required(o, SparseMatrixIndexCSX::VT_INDPTRBUFFER, "indptrBuffer"); + self.fbb_ + .required(o, SparseMatrixIndexCSX::VT_INDICESTYPE, "indicesType"); + self.fbb_ + .required(o, SparseMatrixIndexCSX::VT_INDICESBUFFER, "indicesBuffer"); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for SparseMatrixIndexCSX<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("SparseMatrixIndexCSX"); - ds.field("compressedAxis", &self.compressedAxis()); - ds.field("indptrType", &self.indptrType()); - ds.field("indptrBuffer", &self.indptrBuffer()); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesBuffer", &self.indicesBuffer()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseMatrixIndexCSX"); + ds.field("compressedAxis", &self.compressedAxis()); + ds.field("indptrType", &self.indptrType()); + ds.field("indptrBuffer", &self.indptrBuffer()); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesBuffer", &self.indicesBuffer()); + ds.finish() + } } pub enum SparseTensorIndexCSFOffset {} #[derive(Copy, Clone, PartialEq)] /// Compressed Sparse Fiber (CSF) sparse tensor index. pub struct SparseTensorIndexCSF<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensorIndexCSF<'a> { - type Inner = SparseTensorIndexCSF<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } + type Inner = SparseTensorIndexCSF<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } } impl<'a> SparseTensorIndexCSF<'a> { - pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 4; - pub const VT_INDPTRBUFFERS: flatbuffers::VOffsetT = 6; - pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 8; - pub const VT_INDICESBUFFERS: flatbuffers::VOffsetT = 10; - pub const VT_AXISORDER: flatbuffers::VOffsetT = 12; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensorIndexCSF { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorIndexCSFArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorIndexCSFBuilder::new(_fbb); - if let Some(x) = args.axisOrder { builder.add_axisOrder(x); } - if let Some(x) = args.indicesBuffers { builder.add_indicesBuffers(x); } - if let Some(x) = args.indicesType { builder.add_indicesType(x); } - if let Some(x) = args.indptrBuffers { builder.add_indptrBuffers(x); } - if let Some(x) = args.indptrType { builder.add_indptrType(x); } - builder.finish() - } - - - /// CSF is a generalization of compressed sparse row (CSR) index. - /// See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) - /// - /// CSF index recursively compresses each dimension of a tensor into a set - /// of prefix trees. Each path from a root to leaf forms one tensor - /// non-zero index. CSF is implemented with two arrays of buffers and one - /// arrays of integers. - /// - /// For example, let X be a 2x3x4x5 tensor and let it have the following - /// 8 non-zero values: - /// ```text - /// X[0, 0, 0, 1] := 1 - /// X[0, 0, 0, 2] := 2 - /// X[0, 1, 0, 0] := 3 - /// X[0, 1, 0, 2] := 4 - /// X[0, 1, 1, 0] := 5 - /// X[1, 1, 1, 0] := 6 - /// X[1, 1, 1, 1] := 7 - /// X[1, 1, 1, 2] := 8 - /// ``` - /// As a prefix tree this would be represented as: - /// ```text - /// 0 1 - /// / \ | - /// 0 1 1 - /// / / \ | - /// 0 0 1 1 - /// /| /| | /| | - /// 1 2 0 2 0 0 1 2 - /// ``` - /// The type of values in indptrBuffers - #[inline] - pub fn indptrType(&self) -> Int<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(SparseTensorIndexCSF::VT_INDPTRTYPE, None).unwrap()} - } - /// indptrBuffers stores the sparsity structure. - /// Each two consecutive dimensions in a tensor correspond to a buffer in - /// indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` - /// and `indptrBuffers[dim][i + 1]` signify a range of nodes in - /// `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. - /// - /// For example, the indptrBuffers for the above X is: - /// ```text - /// indptrBuffer(X) = [ - /// [0, 2, 3], - /// [0, 1, 3, 4], - /// [0, 2, 4, 5, 8] - /// ]. - /// ``` - #[inline] - pub fn indptrBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_INDPTRBUFFERS, None).unwrap()} - } - /// The type of values in indicesBuffers - #[inline] - pub fn indicesType(&self) -> Int<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(SparseTensorIndexCSF::VT_INDICESTYPE, None).unwrap()} - } - /// indicesBuffers stores values of nodes. - /// Each tensor dimension corresponds to a buffer in indicesBuffers. - /// For example, the indicesBuffers for the above X is: - /// ```text - /// indicesBuffer(X) = [ - /// [0, 1], - /// [0, 1, 1], - /// [0, 0, 1, 1], - /// [1, 2, 0, 2, 0, 0, 1, 2] - /// ]. - /// ``` - #[inline] - pub fn indicesBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_INDICESBUFFERS, None).unwrap()} - } - /// axisOrder stores the sequence in which dimensions were traversed to - /// produce the prefix tree. - /// For example, the axisOrder for the above X is: - /// ```text - /// axisOrder(X) = [0, 1, 2, 3]. - /// ``` - #[inline] - pub fn axisOrder(&self) -> flatbuffers::Vector<'a, i32> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensorIndexCSF::VT_AXISORDER, None).unwrap()} - } + pub const VT_INDPTRTYPE: flatbuffers::VOffsetT = 4; + pub const VT_INDPTRBUFFERS: flatbuffers::VOffsetT = 6; + pub const VT_INDICESTYPE: flatbuffers::VOffsetT = 8; + pub const VT_INDICESBUFFERS: flatbuffers::VOffsetT = 10; + pub const VT_AXISORDER: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensorIndexCSF { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorIndexCSFArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorIndexCSFBuilder::new(_fbb); + if let Some(x) = args.axisOrder { + builder.add_axisOrder(x); + } + if let Some(x) = args.indicesBuffers { + builder.add_indicesBuffers(x); + } + if let Some(x) = args.indicesType { + builder.add_indicesType(x); + } + if let Some(x) = args.indptrBuffers { + builder.add_indptrBuffers(x); + } + if let Some(x) = args.indptrType { + builder.add_indptrType(x); + } + builder.finish() + } + + /// CSF is a generalization of compressed sparse row (CSR) index. + /// See [smith2017knl](http://shaden.io/pub-files/smith2017knl.pdf) + /// + /// CSF index recursively compresses each dimension of a tensor into a set + /// of prefix trees. Each path from a root to leaf forms one tensor + /// non-zero index. CSF is implemented with two arrays of buffers and one + /// arrays of integers. + /// + /// For example, let X be a 2x3x4x5 tensor and let it have the following + /// 8 non-zero values: + /// ```text + /// X[0, 0, 0, 1] := 1 + /// X[0, 0, 0, 2] := 2 + /// X[0, 1, 0, 0] := 3 + /// X[0, 1, 0, 2] := 4 + /// X[0, 1, 1, 0] := 5 + /// X[1, 1, 1, 0] := 6 + /// X[1, 1, 1, 1] := 7 + /// X[1, 1, 1, 2] := 8 + /// ``` + /// As a prefix tree this would be represented as: + /// ```text + /// 0 1 + /// / \ | + /// 0 1 1 + /// / / \ | + /// 0 0 1 1 + /// /| /| | /| | + /// 1 2 0 2 0 0 1 2 + /// ``` + /// The type of values in indptrBuffers + #[inline] + pub fn indptrType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + SparseTensorIndexCSF::VT_INDPTRTYPE, + None, + ) + .unwrap() + } + } + /// indptrBuffers stores the sparsity structure. + /// Each two consecutive dimensions in a tensor correspond to a buffer in + /// indptrBuffers. A pair of consecutive values at `indptrBuffers[dim][i]` + /// and `indptrBuffers[dim][i + 1]` signify a range of nodes in + /// `indicesBuffers[dim + 1]` who are children of `indicesBuffers[dim][i]` node. + /// + /// For example, the indptrBuffers for the above X is: + /// ```text + /// indptrBuffer(X) = [ + /// [0, 2, 3], + /// [0, 1, 3, 4], + /// [0, 2, 4, 5, 8] + /// ]. + /// ``` + #[inline] + pub fn indptrBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensorIndexCSF::VT_INDPTRBUFFERS, + None, + ) + .unwrap() + } + } + /// The type of values in indicesBuffers + #[inline] + pub fn indicesType(&self) -> Int<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>( + SparseTensorIndexCSF::VT_INDICESTYPE, + None, + ) + .unwrap() + } + } + /// indicesBuffers stores values of nodes. + /// Each tensor dimension corresponds to a buffer in indicesBuffers. + /// For example, the indicesBuffers for the above X is: + /// ```text + /// indicesBuffer(X) = [ + /// [0, 1], + /// [0, 1, 1], + /// [0, 0, 1, 1], + /// [1, 2, 0, 2, 0, 0, 1, 2] + /// ]. + /// ``` + #[inline] + pub fn indicesBuffers(&self) -> flatbuffers::Vector<'a, Buffer> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensorIndexCSF::VT_INDICESBUFFERS, + None, + ) + .unwrap() + } + } + /// axisOrder stores the sequence in which dimensions were traversed to + /// produce the prefix tree. + /// For example, the axisOrder for the above X is: + /// ```text + /// axisOrder(X) = [0, 1, 2, 3]. + /// ``` + #[inline] + pub fn axisOrder(&self) -> flatbuffers::Vector<'a, i32> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensorIndexCSF::VT_AXISORDER, + None, + ) + .unwrap() + } + } } impl flatbuffers::Verifiable for SparseTensorIndexCSF<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("indptrType", Self::VT_INDPTRTYPE, true)? - .visit_field::>>("indptrBuffers", Self::VT_INDPTRBUFFERS, true)? - .visit_field::>("indicesType", Self::VT_INDICESTYPE, true)? - .visit_field::>>("indicesBuffers", Self::VT_INDICESBUFFERS, true)? - .visit_field::>>("axisOrder", Self::VT_AXISORDER, true)? - .finish(); - Ok(()) - } + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>( + "indptrType", + Self::VT_INDPTRTYPE, + true, + )? + .visit_field::>>( + "indptrBuffers", + Self::VT_INDPTRBUFFERS, + true, + )? + .visit_field::>( + "indicesType", + Self::VT_INDICESTYPE, + true, + )? + .visit_field::>>( + "indicesBuffers", + Self::VT_INDICESBUFFERS, + true, + )? + .visit_field::>>( + "axisOrder", + Self::VT_AXISORDER, + true, + )? + .finish(); + Ok(()) + } } pub struct SparseTensorIndexCSFArgs<'a> { pub indptrType: Option>>, @@ -766,520 +980,607 @@ pub struct SparseTensorIndexCSFArgs<'a> { pub axisOrder: Option>>, } impl<'a> Default for SparseTensorIndexCSFArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorIndexCSFArgs { - indptrType: None, // required field - indptrBuffers: None, // required field - indicesType: None, // required field - indicesBuffers: None, // required field - axisOrder: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseTensorIndexCSFArgs { + indptrType: None, // required field + indptrBuffers: None, // required field + indicesType: None, // required field + indicesBuffers: None, // required field + axisOrder: None, // required field + } + } } pub struct SparseTensorIndexCSFBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorIndexCSFBuilder<'a, 'b> { - #[inline] - pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDPTRTYPE, indptrType); - } - #[inline] - pub fn add_indptrBuffers(&mut self, indptrBuffers: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDPTRBUFFERS, indptrBuffers); - } - #[inline] - pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDICESTYPE, indicesType); - } - #[inline] - pub fn add_indicesBuffers(&mut self, indicesBuffers: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_INDICESBUFFERS, indicesBuffers); - } - #[inline] - pub fn add_axisOrder(&mut self, axisOrder: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(SparseTensorIndexCSF::VT_AXISORDER, axisOrder); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorIndexCSFBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorIndexCSFBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_.required(o, SparseTensorIndexCSF::VT_INDPTRTYPE,"indptrType"); - self.fbb_.required(o, SparseTensorIndexCSF::VT_INDPTRBUFFERS,"indptrBuffers"); - self.fbb_.required(o, SparseTensorIndexCSF::VT_INDICESTYPE,"indicesType"); - self.fbb_.required(o, SparseTensorIndexCSF::VT_INDICESBUFFERS,"indicesBuffers"); - self.fbb_.required(o, SparseTensorIndexCSF::VT_AXISORDER,"axisOrder"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_indptrType(&mut self, indptrType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCSF::VT_INDPTRTYPE, + indptrType, + ); + } + #[inline] + pub fn add_indptrBuffers( + &mut self, + indptrBuffers: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCSF::VT_INDPTRBUFFERS, + indptrBuffers, + ); + } + #[inline] + pub fn add_indicesType(&mut self, indicesType: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCSF::VT_INDICESTYPE, + indicesType, + ); + } + #[inline] + pub fn add_indicesBuffers( + &mut self, + indicesBuffers: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCSF::VT_INDICESBUFFERS, + indicesBuffers, + ); + } + #[inline] + pub fn add_axisOrder( + &mut self, + axisOrder: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + SparseTensorIndexCSF::VT_AXISORDER, + axisOrder, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, + ) -> SparseTensorIndexCSFBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorIndexCSFBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_ + .required(o, SparseTensorIndexCSF::VT_INDPTRTYPE, "indptrType"); + self.fbb_ + .required(o, SparseTensorIndexCSF::VT_INDPTRBUFFERS, "indptrBuffers"); + self.fbb_ + .required(o, SparseTensorIndexCSF::VT_INDICESTYPE, "indicesType"); + self.fbb_ + .required(o, SparseTensorIndexCSF::VT_INDICESBUFFERS, "indicesBuffers"); + self.fbb_ + .required(o, SparseTensorIndexCSF::VT_AXISORDER, "axisOrder"); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for SparseTensorIndexCSF<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("SparseTensorIndexCSF"); - ds.field("indptrType", &self.indptrType()); - ds.field("indptrBuffers", &self.indptrBuffers()); - ds.field("indicesType", &self.indicesType()); - ds.field("indicesBuffers", &self.indicesBuffers()); - ds.field("axisOrder", &self.axisOrder()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensorIndexCSF"); + ds.field("indptrType", &self.indptrType()); + ds.field("indptrBuffers", &self.indptrBuffers()); + ds.field("indicesType", &self.indicesType()); + ds.field("indicesBuffers", &self.indicesBuffers()); + ds.field("axisOrder", &self.axisOrder()); + ds.finish() + } } pub enum SparseTensorOffset {} #[derive(Copy, Clone, PartialEq)] pub struct SparseTensor<'a> { - pub _tab: flatbuffers::Table<'a>, + pub _tab: flatbuffers::Table<'a>, } impl<'a> flatbuffers::Follow<'a> for SparseTensor<'a> { - type Inner = SparseTensor<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } + type Inner = SparseTensor<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } } impl<'a> SparseTensor<'a> { - pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_TYPE_: flatbuffers::VOffsetT = 6; - pub const VT_SHAPE: flatbuffers::VOffsetT = 8; - pub const VT_NON_ZERO_LENGTH: flatbuffers::VOffsetT = 10; - pub const VT_SPARSEINDEX_TYPE: flatbuffers::VOffsetT = 12; - pub const VT_SPARSEINDEX: flatbuffers::VOffsetT = 14; - pub const VT_DATA: flatbuffers::VOffsetT = 16; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - SparseTensor { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, - args: &'args SparseTensorArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = SparseTensorBuilder::new(_fbb); - builder.add_non_zero_length(args.non_zero_length); - if let Some(x) = args.data { builder.add_data(x); } - if let Some(x) = args.sparseIndex { builder.add_sparseIndex(x); } - if let Some(x) = args.shape { builder.add_shape(x); } - if let Some(x) = args.type_ { builder.add_type_(x); } - builder.add_sparseIndex_type(args.sparseIndex_type); - builder.add_type_type(args.type_type); - builder.finish() - } - - - #[inline] - pub fn type_type(&self) -> Type { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensor::VT_TYPE_TYPE, Some(Type::NONE)).unwrap()} - } - /// The type of data contained in a value cell. - /// Currently only fixed-width value types are supported, - /// no strings or nested types. - #[inline] - pub fn type_(&self) -> flatbuffers::Table<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensor::VT_TYPE_, None).unwrap()} - } - /// The dimensions of the tensor, optionally named. - #[inline] - pub fn shape(&self) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>>(SparseTensor::VT_SHAPE, None).unwrap()} - } - /// The number of non-zero values in a sparse tensor. - #[inline] - pub fn non_zero_length(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensor::VT_NON_ZERO_LENGTH, Some(0)).unwrap()} - } - #[inline] - pub fn sparseIndex_type(&self) -> SparseTensorIndex { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensor::VT_SPARSEINDEX_TYPE, Some(SparseTensorIndex::NONE)).unwrap()} - } - /// Sparse tensor index - #[inline] - pub fn sparseIndex(&self) -> flatbuffers::Table<'a> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(SparseTensor::VT_SPARSEINDEX, None).unwrap()} - } - /// The location and size of the tensor's data - #[inline] - pub fn data(&self) -> &'a Buffer { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(SparseTensor::VT_DATA, None).unwrap()} - } - #[inline] - #[allow(non_snake_case)] - pub fn type_as_null(&self) -> Option> { - if self.type_type() == Type::Null { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Null::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_int(&self) -> Option> { - if self.type_type() == Type::Int { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Int::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_floating_point(&self) -> Option> { - if self.type_type() == Type::FloatingPoint { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { FloatingPoint::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_binary(&self) -> Option> { - if self.type_type() == Type::Binary { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Binary::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_utf_8(&self) -> Option> { - if self.type_type() == Type::Utf8 { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Utf8::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_bool(&self) -> Option> { - if self.type_type() == Type::Bool { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Bool::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_decimal(&self) -> Option> { - if self.type_type() == Type::Decimal { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Decimal::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_date(&self) -> Option> { - if self.type_type() == Type::Date { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Date::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_time(&self) -> Option> { - if self.type_type() == Type::Time { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Time::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_timestamp(&self) -> Option> { - if self.type_type() == Type::Timestamp { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Timestamp::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_interval(&self) -> Option> { - if self.type_type() == Type::Interval { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Interval::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_list(&self) -> Option> { - if self.type_type() == Type::List { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { List::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_struct_(&self) -> Option> { - if self.type_type() == Type::Struct_ { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Struct_::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_union(&self) -> Option> { - if self.type_type() == Type::Union { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Union::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_fixed_size_binary(&self) -> Option> { - if self.type_type() == Type::FixedSizeBinary { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { FixedSizeBinary::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_fixed_size_list(&self) -> Option> { - if self.type_type() == Type::FixedSizeList { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { FixedSizeList::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_map(&self) -> Option> { - if self.type_type() == Type::Map { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Map::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_duration(&self) -> Option> { - if self.type_type() == Type::Duration { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { Duration::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_binary(&self) -> Option> { - if self.type_type() == Type::LargeBinary { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { LargeBinary::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_utf_8(&self) -> Option> { - if self.type_type() == Type::LargeUtf8 { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { LargeUtf8::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn type_as_large_list(&self) -> Option> { - if self.type_type() == Type::LargeList { - let u = self.type_(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { LargeList::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_tensor_index_coo(&self) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCOO { - let u = self.sparseIndex(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { SparseTensorIndexCOO::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_matrix_index_csx(&self) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseMatrixIndexCSX { - let u = self.sparseIndex(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { SparseMatrixIndexCSX::init_from_table(u) }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn sparseIndex_as_sparse_tensor_index_csf(&self) -> Option> { - if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCSF { - let u = self.sparseIndex(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - Some(unsafe { SparseTensorIndexCSF::init_from_table(u) }) - } else { - None - } - } + pub const VT_TYPE_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_TYPE_: flatbuffers::VOffsetT = 6; + pub const VT_SHAPE: flatbuffers::VOffsetT = 8; + pub const VT_NON_ZERO_LENGTH: flatbuffers::VOffsetT = 10; + pub const VT_SPARSEINDEX_TYPE: flatbuffers::VOffsetT = 12; + pub const VT_SPARSEINDEX: flatbuffers::VOffsetT = 14; + pub const VT_DATA: flatbuffers::VOffsetT = 16; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + SparseTensor { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>, + args: &'args SparseTensorArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = SparseTensorBuilder::new(_fbb); + builder.add_non_zero_length(args.non_zero_length); + if let Some(x) = args.data { + builder.add_data(x); + } + if let Some(x) = args.sparseIndex { + builder.add_sparseIndex(x); + } + if let Some(x) = args.shape { + builder.add_shape(x); + } + if let Some(x) = args.type_ { + builder.add_type_(x); + } + builder.add_sparseIndex_type(args.sparseIndex_type); + builder.add_type_type(args.type_type); + builder.finish() + } + + #[inline] + pub fn type_type(&self) -> Type { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseTensor::VT_TYPE_TYPE, Some(Type::NONE)) + .unwrap() + } + } + /// The type of data contained in a value cell. + /// Currently only fixed-width value types are supported, + /// no strings or nested types. + #[inline] + pub fn type_(&self) -> flatbuffers::Table<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensor::VT_TYPE_, + None, + ) + .unwrap() + } + } + /// The dimensions of the tensor, optionally named. + #[inline] + pub fn shape( + &self, + ) -> flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>, + >>(SparseTensor::VT_SHAPE, None) + .unwrap() + } + } + /// The number of non-zero values in a sparse tensor. + #[inline] + pub fn non_zero_length(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseTensor::VT_NON_ZERO_LENGTH, Some(0)) + .unwrap() + } + } + #[inline] + pub fn sparseIndex_type(&self) -> SparseTensorIndex { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + SparseTensor::VT_SPARSEINDEX_TYPE, + Some(SparseTensorIndex::NONE), + ) + .unwrap() + } + } + /// Sparse tensor index + #[inline] + pub fn sparseIndex(&self) -> flatbuffers::Table<'a> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + SparseTensor::VT_SPARSEINDEX, + None, + ) + .unwrap() + } + } + /// The location and size of the tensor's data + #[inline] + pub fn data(&self) -> &'a Buffer { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(SparseTensor::VT_DATA, None) + .unwrap() + } + } + #[inline] + #[allow(non_snake_case)] + pub fn type_as_null(&self) -> Option> { + if self.type_type() == Type::Null { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Null::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_int(&self) -> Option> { + if self.type_type() == Type::Int { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Int::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_floating_point(&self) -> Option> { + if self.type_type() == Type::FloatingPoint { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FloatingPoint::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_binary(&self) -> Option> { + if self.type_type() == Type::Binary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Binary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_utf_8(&self) -> Option> { + if self.type_type() == Type::Utf8 { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Utf8::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_bool(&self) -> Option> { + if self.type_type() == Type::Bool { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Bool::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_decimal(&self) -> Option> { + if self.type_type() == Type::Decimal { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Decimal::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_date(&self) -> Option> { + if self.type_type() == Type::Date { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Date::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_time(&self) -> Option> { + if self.type_type() == Type::Time { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Time::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_timestamp(&self) -> Option> { + if self.type_type() == Type::Timestamp { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Timestamp::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_interval(&self) -> Option> { + if self.type_type() == Type::Interval { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Interval::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_list(&self) -> Option> { + if self.type_type() == Type::List { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { List::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_struct_(&self) -> Option> { + if self.type_type() == Type::Struct_ { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Struct_::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_union(&self) -> Option> { + if self.type_type() == Type::Union { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Union::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_fixed_size_binary(&self) -> Option> { + if self.type_type() == Type::FixedSizeBinary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeBinary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_fixed_size_list(&self) -> Option> { + if self.type_type() == Type::FixedSizeList { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { FixedSizeList::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_map(&self) -> Option> { + if self.type_type() == Type::Map { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Map::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_duration(&self) -> Option> { + if self.type_type() == Type::Duration { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { Duration::init_from_table(u) }) + } else { + None + } + } + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_binary(&self) -> Option> { + if self.type_type() == Type::LargeBinary { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeBinary::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_utf_8(&self) -> Option> { + if self.type_type() == Type::LargeUtf8 { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeUtf8::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn type_as_large_list(&self) -> Option> { + if self.type_type() == Type::LargeList { + let u = self.type_(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { LargeList::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_tensor_index_coo( + &self, + ) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCOO { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseTensorIndexCOO::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_matrix_index_csx( + &self, + ) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseMatrixIndexCSX { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseMatrixIndexCSX::init_from_table(u) }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn sparseIndex_as_sparse_tensor_index_csf( + &self, + ) -> Option> { + if self.sparseIndex_type() == SparseTensorIndex::SparseTensorIndexCSF { + let u = self.sparseIndex(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + Some(unsafe { SparseTensorIndexCSF::init_from_table(u) }) + } else { + None + } + } } impl flatbuffers::Verifiable for SparseTensor<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use flatbuffers::Verifiable; - v.visit_table(pos)? + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use flatbuffers::Verifiable; + v.visit_table(pos)? .visit_union::("type_type", Self::VT_TYPE_TYPE, "type_", Self::VT_TYPE_, true, |key, v, pos| { match key { Type::Null => v.verify_union_variant::>("Type::Null", pos), @@ -1318,275 +1619,377 @@ impl flatbuffers::Verifiable for SparseTensor<'_> { })? .visit_field::("data", Self::VT_DATA, true)? .finish(); - Ok(()) - } + Ok(()) + } } pub struct SparseTensorArgs<'a> { pub type_type: Type, pub type_: Option>, - pub shape: Option>>>>, + pub shape: Option< + flatbuffers::WIPOffset< + flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, + >, + >, pub non_zero_length: i64, pub sparseIndex_type: SparseTensorIndex, pub sparseIndex: Option>, pub data: Option<&'a Buffer>, } impl<'a> Default for SparseTensorArgs<'a> { - #[inline] - fn default() -> Self { - SparseTensorArgs { - type_type: Type::NONE, - type_: None, // required field - shape: None, // required field - non_zero_length: 0, - sparseIndex_type: SparseTensorIndex::NONE, - sparseIndex: None, // required field - data: None, // required field - } - } + #[inline] + fn default() -> Self { + SparseTensorArgs { + type_type: Type::NONE, + type_: None, // required field + shape: None, // required field + non_zero_length: 0, + sparseIndex_type: SparseTensorIndex::NONE, + sparseIndex: None, // required field + data: None, // required field + } + } } pub struct SparseTensorBuilder<'a: 'b, 'b> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, - start_: flatbuffers::WIPOffset, + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>, + start_: flatbuffers::WIPOffset, } impl<'a: 'b, 'b> SparseTensorBuilder<'a, 'b> { - #[inline] - pub fn add_type_type(&mut self, type_type: Type) { - self.fbb_.push_slot::(SparseTensor::VT_TYPE_TYPE, type_type, Type::NONE); - } - #[inline] - pub fn add_type_(&mut self, type_: flatbuffers::WIPOffset) { - self.fbb_.push_slot_always::>(SparseTensor::VT_TYPE_, type_); - } - #[inline] - pub fn add_shape(&mut self, shape: flatbuffers::WIPOffset>>>) { - self.fbb_.push_slot_always::>(SparseTensor::VT_SHAPE, shape); - } - #[inline] - pub fn add_non_zero_length(&mut self, non_zero_length: i64) { - self.fbb_.push_slot::(SparseTensor::VT_NON_ZERO_LENGTH, non_zero_length, 0); - } - #[inline] - pub fn add_sparseIndex_type(&mut self, sparseIndex_type: SparseTensorIndex) { - self.fbb_.push_slot::(SparseTensor::VT_SPARSEINDEX_TYPE, sparseIndex_type, SparseTensorIndex::NONE); - } - #[inline] - pub fn add_sparseIndex(&mut self, sparseIndex: flatbuffers::WIPOffset) { - self.fbb_.push_slot_always::>(SparseTensor::VT_SPARSEINDEX, sparseIndex); - } - #[inline] - pub fn add_data(&mut self, data: &Buffer) { - self.fbb_.push_slot_always::<&Buffer>(SparseTensor::VT_DATA, data); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SparseTensorBuilder<'a, 'b> { - let start = _fbb.start_table(); - SparseTensorBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - self.fbb_.required(o, SparseTensor::VT_TYPE_,"type_"); - self.fbb_.required(o, SparseTensor::VT_SHAPE,"shape"); - self.fbb_.required(o, SparseTensor::VT_SPARSEINDEX,"sparseIndex"); - self.fbb_.required(o, SparseTensor::VT_DATA,"data"); - flatbuffers::WIPOffset::new(o.value()) - } + #[inline] + pub fn add_type_type(&mut self, type_type: Type) { + self.fbb_ + .push_slot::(SparseTensor::VT_TYPE_TYPE, type_type, Type::NONE); + } + #[inline] + pub fn add_type_( + &mut self, + type_: flatbuffers::WIPOffset, + ) { + self.fbb_ + .push_slot_always::>(SparseTensor::VT_TYPE_, type_); + } + #[inline] + pub fn add_shape( + &mut self, + shape: flatbuffers::WIPOffset< + flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, + >, + ) { + self.fbb_ + .push_slot_always::>(SparseTensor::VT_SHAPE, shape); + } + #[inline] + pub fn add_non_zero_length(&mut self, non_zero_length: i64) { + self.fbb_ + .push_slot::(SparseTensor::VT_NON_ZERO_LENGTH, non_zero_length, 0); + } + #[inline] + pub fn add_sparseIndex_type(&mut self, sparseIndex_type: SparseTensorIndex) { + self.fbb_.push_slot::( + SparseTensor::VT_SPARSEINDEX_TYPE, + sparseIndex_type, + SparseTensorIndex::NONE, + ); + } + #[inline] + pub fn add_sparseIndex( + &mut self, + sparseIndex: flatbuffers::WIPOffset, + ) { + self.fbb_.push_slot_always::>( + SparseTensor::VT_SPARSEINDEX, + sparseIndex, + ); + } + #[inline] + pub fn add_data(&mut self, data: &Buffer) { + self.fbb_ + .push_slot_always::<&Buffer>(SparseTensor::VT_DATA, data); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, + ) -> SparseTensorBuilder<'a, 'b> { + let start = _fbb.start_table(); + SparseTensorBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, SparseTensor::VT_TYPE_, "type_"); + self.fbb_.required(o, SparseTensor::VT_SHAPE, "shape"); + self.fbb_ + .required(o, SparseTensor::VT_SPARSEINDEX, "sparseIndex"); + self.fbb_.required(o, SparseTensor::VT_DATA, "data"); + flatbuffers::WIPOffset::new(o.value()) + } } impl core::fmt::Debug for SparseTensor<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("SparseTensor"); - ds.field("type_type", &self.type_type()); - match self.type_type() { - Type::Null => { - if let Some(x) = self.type_as_null() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Int => { - if let Some(x) = self.type_as_int() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::FloatingPoint => { - if let Some(x) = self.type_as_floating_point() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Binary => { - if let Some(x) = self.type_as_binary() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Utf8 => { - if let Some(x) = self.type_as_utf_8() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Bool => { - if let Some(x) = self.type_as_bool() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Decimal => { - if let Some(x) = self.type_as_decimal() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Date => { - if let Some(x) = self.type_as_date() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Time => { - if let Some(x) = self.type_as_time() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Timestamp => { - if let Some(x) = self.type_as_timestamp() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Interval => { - if let Some(x) = self.type_as_interval() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::List => { - if let Some(x) = self.type_as_list() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Struct_ => { - if let Some(x) = self.type_as_struct_() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Union => { - if let Some(x) = self.type_as_union() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::FixedSizeBinary => { - if let Some(x) = self.type_as_fixed_size_binary() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::FixedSizeList => { - if let Some(x) = self.type_as_fixed_size_list() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Map => { - if let Some(x) = self.type_as_map() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::Duration => { - if let Some(x) = self.type_as_duration() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::LargeBinary => { - if let Some(x) = self.type_as_large_binary() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::LargeUtf8 => { - if let Some(x) = self.type_as_large_utf_8() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Type::LargeList => { - if let Some(x) = self.type_as_large_list() { - ds.field("type_", &x) - } else { - ds.field("type_", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - _ => { - let x: Option<()> = None; - ds.field("type_", &x) - }, - }; - ds.field("shape", &self.shape()); - ds.field("non_zero_length", &self.non_zero_length()); - ds.field("sparseIndex_type", &self.sparseIndex_type()); - match self.sparseIndex_type() { - SparseTensorIndex::SparseTensorIndexCOO => { - if let Some(x) = self.sparseIndex_as_sparse_tensor_index_coo() { - ds.field("sparseIndex", &x) - } else { - ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - SparseTensorIndex::SparseMatrixIndexCSX => { - if let Some(x) = self.sparseIndex_as_sparse_matrix_index_csx() { - ds.field("sparseIndex", &x) - } else { - ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - SparseTensorIndex::SparseTensorIndexCSF => { - if let Some(x) = self.sparseIndex_as_sparse_tensor_index_csf() { - ds.field("sparseIndex", &x) - } else { - ds.field("sparseIndex", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - _ => { - let x: Option<()> = None; - ds.field("sparseIndex", &x) - }, - }; - ds.field("data", &self.data()); - ds.finish() - } + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("SparseTensor"); + ds.field("type_type", &self.type_type()); + match self.type_type() { + Type::Null => { + if let Some(x) = self.type_as_null() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Int => { + if let Some(x) = self.type_as_int() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::FloatingPoint => { + if let Some(x) = self.type_as_floating_point() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Binary => { + if let Some(x) = self.type_as_binary() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Utf8 => { + if let Some(x) = self.type_as_utf_8() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Bool => { + if let Some(x) = self.type_as_bool() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Decimal => { + if let Some(x) = self.type_as_decimal() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Date => { + if let Some(x) = self.type_as_date() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Time => { + if let Some(x) = self.type_as_time() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Timestamp => { + if let Some(x) = self.type_as_timestamp() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Interval => { + if let Some(x) = self.type_as_interval() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::List => { + if let Some(x) = self.type_as_list() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Struct_ => { + if let Some(x) = self.type_as_struct_() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Union => { + if let Some(x) = self.type_as_union() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::FixedSizeBinary => { + if let Some(x) = self.type_as_fixed_size_binary() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::FixedSizeList => { + if let Some(x) = self.type_as_fixed_size_list() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Map => { + if let Some(x) = self.type_as_map() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::Duration => { + if let Some(x) = self.type_as_duration() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::LargeBinary => { + if let Some(x) = self.type_as_large_binary() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::LargeUtf8 => { + if let Some(x) = self.type_as_large_utf_8() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Type::LargeList => { + if let Some(x) = self.type_as_large_list() { + ds.field("type_", &x) + } else { + ds.field( + "type_", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + _ => { + let x: Option<()> = None; + ds.field("type_", &x) + } + }; + ds.field("shape", &self.shape()); + ds.field("non_zero_length", &self.non_zero_length()); + ds.field("sparseIndex_type", &self.sparseIndex_type()); + match self.sparseIndex_type() { + SparseTensorIndex::SparseTensorIndexCOO => { + if let Some(x) = self.sparseIndex_as_sparse_tensor_index_coo() { + ds.field("sparseIndex", &x) + } else { + ds.field( + "sparseIndex", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + SparseTensorIndex::SparseMatrixIndexCSX => { + if let Some(x) = self.sparseIndex_as_sparse_matrix_index_csx() { + ds.field("sparseIndex", &x) + } else { + ds.field( + "sparseIndex", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + SparseTensorIndex::SparseTensorIndexCSF => { + if let Some(x) = self.sparseIndex_as_sparse_tensor_index_csf() { + ds.field("sparseIndex", &x) + } else { + ds.field( + "sparseIndex", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + _ => { + let x: Option<()> = None; + ds.field("sparseIndex", &x) + } + }; + ds.field("data", &self.data()); + ds.finish() + } } #[inline] /// Verifies that a buffer of bytes contains a `SparseTensor` @@ -1595,8 +1998,10 @@ impl core::fmt::Debug for SparseTensor<'_> { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_sparse_tensor_unchecked`. -pub fn root_as_sparse_tensor(buf: &[u8]) -> Result { - flatbuffers::root::(buf) +pub fn root_as_sparse_tensor( + buf: &[u8], +) -> Result { + flatbuffers::root::(buf) } #[inline] /// Verifies that a buffer of bytes contains a size prefixed @@ -1605,8 +2010,10 @@ pub fn root_as_sparse_tensor(buf: &[u8]) -> Result Result { - flatbuffers::size_prefixed_root::(buf) +pub fn size_prefixed_root_as_sparse_tensor( + buf: &[u8], +) -> Result { + flatbuffers::size_prefixed_root::(buf) } #[inline] /// Verifies, with the given options, that a buffer of bytes @@ -1616,10 +2023,10 @@ pub fn size_prefixed_root_as_sparse_tensor(buf: &[u8]) -> Result( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) + flatbuffers::root_with_opts::>(opts, buf) } #[inline] /// Verifies, with the given verifier options, that a buffer of @@ -1629,33 +2036,37 @@ pub fn root_as_sparse_tensor_with_opts<'b, 'o>( /// previous, unchecked, behavior use /// `root_as_sparse_tensor_unchecked`. pub fn size_prefixed_root_as_sparse_tensor_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], ) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a SparseTensor and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `SparseTensor`. pub unsafe fn root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor { - flatbuffers::root_unchecked::(buf) + flatbuffers::root_unchecked::(buf) } #[inline] /// Assumes, without verification, that a buffer of bytes contains a size prefixed SparseTensor and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `SparseTensor`. pub unsafe fn size_prefixed_root_as_sparse_tensor_unchecked(buf: &[u8]) -> SparseTensor { - flatbuffers::size_prefixed_root_unchecked::(buf) + flatbuffers::size_prefixed_root_unchecked::(buf) } #[inline] pub fn finish_sparse_tensor_buffer<'a, 'b>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, - root: flatbuffers::WIPOffset>) { - fbb.finish(root, None); + root: flatbuffers::WIPOffset>, +) { + fbb.finish(root, None); } #[inline] -pub fn finish_size_prefixed_sparse_tensor_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset>) { - fbb.finish_size_prefixed(root, None); +pub fn finish_size_prefixed_sparse_tensor_buffer<'a, 'b>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, + root: flatbuffers::WIPOffset>, +) { + fbb.finish_size_prefixed(root, None); }