pub struct VectorRef<'a>(/* private fields */);Expand description
A borrowed dense vector of f32 components.
A zero-copy view over a &[f32], for passing query vectors without taking
ownership. It is Copy. With the serde feature it derives
Serialize only — a borrowed view cannot be
deserialized into, since there is nowhere to own the decoded data.
§Examples
use iqdb_types::VectorRef;
let data = [1.0, 0.0, 0.0];
let v = VectorRef::from(&data[..]);
assert_eq!(v.dim(), 3);
assert_eq!(v.as_slice(), &[1.0, 0.0, 0.0]);Implementations§
Source§impl<'a> VectorRef<'a>
impl<'a> VectorRef<'a>
Sourcepub fn as_slice(&self) -> &[f32]
pub fn as_slice(&self) -> &[f32]
Borrows the components as a slice.
§Examples
use iqdb_types::VectorRef;
let data = [0.5, 0.5];
assert_eq!(VectorRef::from(&data[..]).as_slice(), &[0.5, 0.5]);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of components.
§Examples
use iqdb_types::VectorRef;
let data = [1.0, 2.0];
assert_eq!(VectorRef::from(&data[..]).len(), 2);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the view has no components.
§Examples
use iqdb_types::VectorRef;
let empty: [f32; 0] = [];
assert!(VectorRef::from(&empty[..]).is_empty());Sourcepub fn dim(&self) -> usize
pub fn dim(&self) -> usize
Returns the dimensionality of the view (its component count).
§Examples
use iqdb_types::VectorRef;
let data = [1.0, 2.0, 3.0];
assert_eq!(VectorRef::from(&data[..]).dim(), 3);Sourcepub fn into_inner(self) -> &'a [f32]
pub fn into_inner(self) -> &'a [f32]
Returns the borrowed slice with its original lifetime.
§Examples
use iqdb_types::VectorRef;
let data = [1.0, 2.0];
let v = VectorRef::from(&data[..]);
let slice: &[f32] = v.into_inner();
assert_eq!(slice, &[1.0, 2.0]);Trait Implementations§
impl<'a> Copy for VectorRef<'a>
Source§impl<'a> PartialEq for VectorRef<'a>
impl<'a> PartialEq for VectorRef<'a>
impl<'a> StructuralPartialEq for VectorRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for VectorRef<'a>
impl<'a> RefUnwindSafe for VectorRef<'a>
impl<'a> Send for VectorRef<'a>
impl<'a> Sync for VectorRef<'a>
impl<'a> Unpin for VectorRef<'a>
impl<'a> UnsafeUnpin for VectorRef<'a>
impl<'a> UnwindSafe for VectorRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more