diff --git a/diskann-utils/src/lib.rs b/diskann-utils/src/lib.rs index 089e0dece..23968c8f0 100644 --- a/diskann-utils/src/lib.rs +++ b/diskann-utils/src/lib.rs @@ -9,9 +9,6 @@ compile_error!("diskann-utils assumes little-endian targets"); pub mod reborrow; pub use reborrow::{Reborrow, ReborrowMut}; -pub mod lifetime; -pub use lifetime::WithLifetime; - pub mod future; pub mod io; diff --git a/diskann-utils/src/lifetime.rs b/diskann-utils/src/lifetime.rs deleted file mode 100644 index f6e85e5f9..000000000 --- a/diskann-utils/src/lifetime.rs +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT license. - */ - -use std::{default::Default, marker::PhantomData}; - -/// A utility `'static` compatible trait adding a lifetime to a type. -pub trait WithLifetime: Send + Sync + 'static { - /// The associated type with a lifetime. - type Of<'a>: Send + Sync; -} - -/// A [`WithLifetime`] annotator for `'static` types that discards the generic lifetime. -/// -/// ``` -/// use diskann_utils::{WithLifetime, lifetime::Static}; -/// -/// fn foo(_: T::Of<'_>) {} -/// -/// let x = f32::default(); -/// foo::>(x); -/// ``` -#[derive(Debug, Clone, Copy)] -pub struct Static { - _type: PhantomData, -} - -const _: () = assert!(std::mem::size_of::>() == 0); - -impl Static { - /// Construct a new `Static` zero sized type. - pub const fn new() -> Self { - Self { _type: PhantomData } - } -} - -impl Default for Static { - fn default() -> Self { - Self::new() - } -} - -impl WithLifetime for Static -where - T: Send + Sync + 'static, -{ - type Of<'a> = T; -} - -/// A [`WithLifetime`] annotator for slices. -/// -/// ``` -/// use diskann_utils::{WithLifetime, lifetime::Slice}; -/// -/// fn foo(x: T::Of<'_>) {} -/// -/// let v = vec![1usize, 2, 3]; -/// foo::>(&v); -/// assert_eq!(v.len(), 3); -/// ``` -#[derive(Debug, Clone, Copy)] -pub struct Slice { - _type: PhantomData, -} - -impl Slice { - pub const fn new() -> Self { - Self { _type: PhantomData } - } -} - -impl Default for Slice { - fn default() -> Self { - Self::new() - } -} - -impl WithLifetime for Slice -where - T: Send + Sync + 'static, -{ - type Of<'a> = &'a [T]; -} - -/////////// -// Tests // -/////////// - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_static() { - fn foo(x: T::Of<'_>) -> T::Of<'_> - where - T: WithLifetime, - for<'a> T::Of<'a>: 'static, - { - x - } - - let x = f32::default(); - assert_eq!(foo::>(x), 0.0); - - const _: Static = Static::new(); - - let _ = Static::::default(); - } - - #[test] - fn test_slice() { - fn foo(x: T::Of<'_>) -> f32 - where - T: for<'a> WithLifetime = &'a [f32]>, - { - x.iter().sum() - } - - let x = vec![1.0, 2.0, 3.0]; - assert_eq!(foo::>(&x), 6.0); - - const _: Slice = Slice::new(); - let _ = Slice::::default(); - } -}