pub struct VectorBody<'a> { /* private fields */ }Expand description
A vector record’s value, borrowed.
Decoding does not copy the coordinates and does not check them. What it checks is that the header is one this version understands and that the coordinates that the header claims are all there, which is what stops a short or corrupt record from being read as a vector of the wrong length.
Implementations§
Source§impl<'a> VectorBody<'a>
impl<'a> VectorBody<'a>
Sourcepub fn encode(values: &[f32], into: &mut [u8]) -> Result<usize>
pub fn encode(values: &[f32], into: &mut [u8]) -> Result<usize>
Writes values into into and says how many bytes that took.
§Errors
Code::Invalid if the dimension is out of range, if into is too
short, or if any coordinate is not finite.
The last one is a refusal at the boundary rather than a thing to sort out later. A NaN coordinate makes every distance involving that vector a NaN, a NaN compares false against everything, and the result is not an error anywhere: the vector simply never wins and never loses, and it quietly distorts the centroid of whatever partition it lands in. That is a bug report about recall six months later, and it costs one pass over a buffer that is being copied anyway to make it impossible.
Sourcepub fn decode(bytes: &'a [u8]) -> Result<VectorBody<'a>>
pub fn decode(bytes: &'a [u8]) -> Result<VectorBody<'a>>
Reads the header back and borrows the coordinates.
§Errors
Code::Corrupt if the header is not one this version understands or
if the record is not as long as its own header says it is.
Sourcepub fn read_into(&self, out: &mut [f32]) -> Result<()>
pub fn read_into(&self, out: &mut [f32]) -> Result<()>
Copies the coordinates into out.
§Errors
Code::Invalid if out is not exactly dim long. Not a
prefix and not a longer buffer, because both of those are a caller that
thinks the collection has a different dimension than it does, and the
only useful moment to say so is here.
Trait Implementations§
Source§impl<'a> Clone for VectorBody<'a>
impl<'a> Clone for VectorBody<'a>
Source§fn clone(&self) -> VectorBody<'a>
fn clone(&self) -> VectorBody<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more