BulkLoader: rename set_* methods to with_* methods

pull/705/head
Tpt 11 months ago committed by Thomas Tanon
parent 4084acb9b8
commit 604d1bbe2e
  1. 8
      lib/src/storage/mod.rs
  2. 29
      lib/src/store.rs

@ -1193,6 +1193,7 @@ impl<'a> StorageWriter<'a> {
} }
#[cfg(not(target_family = "wasm"))] #[cfg(not(target_family = "wasm"))]
#[must_use]
pub struct StorageBulkLoader { pub struct StorageBulkLoader {
storage: Storage, storage: Storage,
hooks: Vec<Box<dyn Fn(u64)>>, hooks: Vec<Box<dyn Fn(u64)>>,
@ -1211,19 +1212,16 @@ impl StorageBulkLoader {
} }
} }
#[must_use] pub fn with_num_threads(mut self, num_threads: usize) -> Self {
pub fn set_num_threads(mut self, num_threads: usize) -> Self {
self.num_threads = Some(num_threads); self.num_threads = Some(num_threads);
self self
} }
#[must_use] pub fn with_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self {
pub fn set_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self {
self.max_memory_size = Some(max_memory_size); self.max_memory_size = Some(max_memory_size);
self self
} }
#[must_use]
pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self { pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self {
self.hooks.push(Box::new(callback)); self.hooks.push(Box::new(callback));
self self

@ -1503,8 +1503,8 @@ impl Iterator for GraphNameIter {
/// Results might get weird if you delete data during the loading process. /// Results might get weird if you delete data during the loading process.
/// ///
/// <div class="warning">It is optimized for speed.</div> /// <div class="warning">It is optimized for speed.</div>
/// Memory usage is configurable using [`BulkLoader::set_max_memory_size_in_megabytes`] /// Memory usage is configurable using [`BulkLoader::with_max_memory_size_in_megabytes`]
/// and the number of used threads with [`BulkLoader::set_num_threads`]. /// and the number of used threads with [`BulkLoader::with_num_threads`].
/// By default the memory consumption target (excluding the system and RocksDB internal consumption) /// By default the memory consumption target (excluding the system and RocksDB internal consumption)
/// is around 2GB per thread and 2 threads. /// is around 2GB per thread and 2 threads.
/// These targets are considered per loaded file. /// These targets are considered per loaded file.
@ -1527,6 +1527,7 @@ impl Iterator for GraphNameIter {
/// # Result::<_, Box<dyn std::error::Error>>::Ok(()) /// # Result::<_, Box<dyn std::error::Error>>::Ok(())
/// ``` /// ```
#[cfg(not(target_family = "wasm"))] #[cfg(not(target_family = "wasm"))]
#[must_use]
pub struct BulkLoader { pub struct BulkLoader {
storage: StorageBulkLoader, storage: StorageBulkLoader,
on_parse_error: Option<Box<dyn Fn(ParseError) -> Result<(), ParseError>>>, on_parse_error: Option<Box<dyn Fn(ParseError) -> Result<(), ParseError>>>,
@ -1539,12 +1540,17 @@ impl BulkLoader {
/// This number must be at last 2 (one for parsing and one for loading). /// This number must be at last 2 (one for parsing and one for loading).
/// ///
/// The default value is 2. /// The default value is 2.
#[must_use] pub fn with_num_threads(mut self, num_threads: usize) -> Self {
pub fn set_num_threads(mut self, num_threads: usize) -> Self { self.storage = self.storage.with_num_threads(num_threads);
self.storage = self.storage.set_num_threads(num_threads);
self self
} }
#[doc(hidden)]
#[deprecated(note = "Use with_num_threads", since = "0.4.0")]
pub fn set_num_threads(self, num_threads: usize) -> Self {
self.with_num_threads(num_threads)
}
/// Sets a rough idea of the maximal amount of memory to be used by this operation. /// Sets a rough idea of the maximal amount of memory to be used by this operation.
/// ///
/// This number must be at last a few megabytes per thread. /// This number must be at last a few megabytes per thread.
@ -1554,16 +1560,20 @@ impl BulkLoader {
/// (for example if the data contains very long IRIs or literals). /// (for example if the data contains very long IRIs or literals).
/// ///
/// By default, a target 2GB per used thread is used. /// By default, a target 2GB per used thread is used.
#[must_use] pub fn with_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self {
pub fn set_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self {
self.storage = self self.storage = self
.storage .storage
.set_max_memory_size_in_megabytes(max_memory_size); .with_max_memory_size_in_megabytes(max_memory_size);
self self
} }
#[doc(hidden)]
#[deprecated(note = "Use with_max_memory_size_in_megabytes", since = "0.4.0")]
pub fn set_max_memory_size_in_megabytes(self, max_memory_size: usize) -> Self {
self.with_max_memory_size_in_megabytes(max_memory_size)
}
/// Adds a `callback` evaluated from time to time with the number of loaded triples. /// Adds a `callback` evaluated from time to time with the number of loaded triples.
#[must_use]
pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self { pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self {
self.storage = self.storage.on_progress(callback); self.storage = self.storage.on_progress(callback);
self self
@ -1573,7 +1583,6 @@ impl BulkLoader {
/// by returning `Ok` or fail by returning `Err`. /// by returning `Ok` or fail by returning `Err`.
/// ///
/// By default the parsing fails. /// By default the parsing fails.
#[must_use]
pub fn on_parse_error( pub fn on_parse_error(
mut self, mut self,
callback: impl Fn(ParseError) -> Result<(), ParseError> + 'static, callback: impl Fn(ParseError) -> Result<(), ParseError> + 'static,

Loading…
Cancel
Save