1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
mod byte_range_cache;
mod caching_directory;
mod debug_proxy_directory;
mod external_requests;
mod hot_cache_directory;
mod network_directory;

pub use caching_directory::{CachingDirectory, FileStat, FileStats};
pub use debug_proxy_directory::DebugProxyDirectory;
pub use external_requests::{
    DefaultExternalRequestGenerator, ExternalRequest, ExternalRequestGenerator, ExternalRequestGeneratorClone, ExternalResponse, Header, RequestError,
};
pub use hot_cache_directory::{create_hotcache, deserialize_cbor, HotDirectory, StaticDirectoryCache};
pub use network_directory::{NetworkDirectory, NetworkFile};

struct Noop {}

impl std::io::Write for Noop {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        Ok(())
    }
}

impl tantivy::directory::TerminatingWrite for Noop {
    fn terminate_ref(&mut self, _: tantivy::directory::AntiCallToken) -> std::io::Result<()> {
        Ok(())
    }
}

#[macro_export]
macro_rules! write_proxy_directory {
    () => {
        fn atomic_write(&self, path: &Path, data: &[u8]) -> std::io::Result<()> {
            self.underlying.atomic_write(path, data)
        }

        fn delete(&self, path: &Path) -> Result<(), tantivy::directory::error::DeleteError> {
            self.underlying.delete(path)
        }

        async fn delete_async(&self, path: &Path) -> Result<(), tantivy::directory::error::DeleteError> {
            self.underlying.delete_async(path).await
        }

        fn open_write(&self, path: &Path) -> Result<tantivy::directory::WritePtr, tantivy::directory::error::OpenWriteError> {
            self.underlying.open_write(path)
        }

        fn sync_directory(&self) -> std::io::Result<()> {
            self.underlying.sync_directory()
        }

        fn watch(&self, watch_callback: tantivy::directory::WatchCallback) -> tantivy::Result<tantivy::directory::WatchHandle> {
            self.underlying.watch(watch_callback)
        }

        fn acquire_lock(&self, lock: &tantivy::directory::Lock) -> Result<tantivy::directory::DirectoryLock, tantivy::directory::error::LockError> {
            self.underlying.acquire_lock(lock)
        }
    };
}
pub use write_proxy_directory;