Skip to main content

VectorBody

Struct VectorBody 

Source
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>

Source

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.

Source

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.

Source

pub const fn dim(&self) -> usize

How many coordinates the vector has.

Source

pub const fn element(&self) -> Element

How the coordinates are stored.

Source

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.

Source

pub fn at(&self, i: usize) -> Option<f32>

One coordinate, or None past the end.

Source

pub const fn bytes(&self) -> &'a [u8]

The coordinates as they are stored, for a caller that is copying a record rather than reading it.

Trait Implementations§

Source§

impl<'a> Clone for VectorBody<'a>

Source§

fn clone(&self) -> VectorBody<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for VectorBody<'a>

Source§

impl<'a> Debug for VectorBody<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for VectorBody<'a>

§

impl<'a> RefUnwindSafe for VectorBody<'a>

§

impl<'a> Send for VectorBody<'a>

§

impl<'a> Sync for VectorBody<'a>

§

impl<'a> Unpin for VectorBody<'a>

§

impl<'a> UnsafeUnpin for VectorBody<'a>

§

impl<'a> UnwindSafe for VectorBody<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.