use core::num::NonZeroUsize;
use super::SlotHandle;
use crate::{AsyncFulltextWrite, AsyncVectorRead, Connected, FulltextSubset, VectorColumn};
const K: NonZeroUsize = NonZeroUsize::new(10).expect("10 is not zero");
struct Transcript;
struct Caption;
fn poll<F: Future>(future: F) -> F::Output {
use core::{
pin::pin,
task::{Context, Poll, Waker},
};
let mut future = pin!(future);
let mut cx = Context::from_waker(Waker::noop());
loop {
if let Poll::Ready(value) = future.as_mut().poll(&mut cx) {
return value;
}
}
}
#[test]
fn the_brand_carries_no_value() {
let transcripts: SlotHandle<(), Transcript> = SlotHandle::mint(());
let captions: SlotHandle<(), Caption> = SlotHandle::mint(());
assert_eq!(
core::mem::size_of_val(&transcripts),
core::mem::size_of::<()>()
);
assert_eq!(transcripts.engine(), captions.engine());
let () = transcripts.into_engine();
}
#[test]
fn a_clone_keeps_the_brand() {
let one: SlotHandle<u8, Transcript> = SlotHandle::mint(7);
let two = one.clone();
let same: SlotHandle<u8, Transcript> = two;
assert_eq!(one.engine(), same.engine());
}
#[test]
fn the_brand_does_not_borrow_the_declarations_auto_traits() {
struct Unsendable(#[allow(dead_code)] *const u8);
const fn is_send<T: Send + Sync>() {}
const _: () = is_send::<SlotHandle<u8, Unsendable>>();
assert_eq!(
core::mem::size_of::<SlotHandle<u8, Unsendable>>(),
core::mem::size_of::<u8>(),
"and the marker costs no bytes either",
);
}
#[test]
fn the_branded_doors_forward_to_the_engine() {
let mut fulltext: SlotHandle<(), Transcript> = SlotHandle::mint(());
assert_eq!(
poll(fulltext.upsert_document(Connected::new(&(), ()), ())),
Ok(())
);
assert_eq!(
poll(fulltext.search(Connected::new(&(), ()), FulltextSubset::All, "car", K, None)),
Ok(Vec::new())
);
let mut vector: SlotHandle<(), Caption> = SlotHandle::mint(());
assert_eq!(
poll(vector.upsert_vector(Connected::new(&(), ()), ())),
Ok(())
);
assert_eq!(
poll(vector.knn(
Connected::new(&(), ()),
VectorColumn::new("image_embedding"),
&[],
K,
None
)),
Ok(Vec::new())
);
assert_eq!(
poll(AsyncFulltextWrite::upsert(&(), Connected::new(&(), ()), ())),
Ok(())
);
assert_eq!(
poll(AsyncVectorRead::knn(
&(),
Connected::new(&(), ()),
VectorColumn::new("image_embedding"),
&[],
K,
None
)),
Ok(Vec::new())
);
}