pub struct BatchSizeConfig {
pub size: usize,
pub strategy: BatchStrategy,
}Expand description
批量大小配置
对应 Hibernate @BatchSize(size = 100) 注解。
Fields§
§size: usize每批数量
strategy: BatchStrategy抓取策略
Implementations§
Source§impl BatchSizeConfig
impl BatchSizeConfig
Sourcepub fn new(size: usize, strategy: BatchStrategy) -> Self
pub fn new(size: usize, strategy: BatchStrategy) -> Self
创建配置
Sourcepub fn batch_count(&self, total: usize) -> usize
pub fn batch_count(&self, total: usize) -> usize
计算给定总数需要分多少批
§示例
use sz_orm_query::entity_graph::BatchSizeConfig;
let config = BatchSizeConfig::with_size(100);
assert_eq!(config.batch_count(0), 0);
assert_eq!(config.batch_count(1), 1);
assert_eq!(config.batch_count(100), 1);
assert_eq!(config.batch_count(101), 2);
assert_eq!(config.batch_count(250), 3);Sourcepub fn batch_range(&self, batch_index: usize, total: usize) -> Range<usize>
pub fn batch_range(&self, batch_index: usize, total: usize) -> Range<usize>
返回第 batch_index 批的范围(start..end,end 不超过 total)
§示例
use sz_orm_query::entity_graph::BatchSizeConfig;
let config = BatchSizeConfig::with_size(100);
assert_eq!(config.batch_range(0, 250), 0..100);
assert_eq!(config.batch_range(1, 250), 100..200);
assert_eq!(config.batch_range(2, 250), 200..250);Trait Implementations§
Source§impl Clone for BatchSizeConfig
impl Clone for BatchSizeConfig
Source§fn clone(&self) -> BatchSizeConfig
fn clone(&self) -> BatchSizeConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for BatchSizeConfig
Source§impl Debug for BatchSizeConfig
impl Debug for BatchSizeConfig
Auto Trait Implementations§
impl Freeze for BatchSizeConfig
impl RefUnwindSafe for BatchSizeConfig
impl Send for BatchSizeConfig
impl Sync for BatchSizeConfig
impl Unpin for BatchSizeConfig
impl UnsafeUnpin for BatchSizeConfig
impl UnwindSafe for BatchSizeConfig
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