Struct qiniu_upload_manager::PartSize
source · pub struct PartSize(_);
Expand description
分片大小
Implementations§
source§impl PartSize
impl PartSize
sourcepub const fn new_with_non_zero_u64(concurrency: NonZeroU64) -> Self
pub const fn new_with_non_zero_u64(concurrency: NonZeroU64) -> Self
创建分片大小
提供 NonZeroU64
作为并发数类型。
sourcepub fn as_non_zero_u64(&self) -> NonZeroU64
pub fn as_non_zero_u64(&self) -> NonZeroU64
获取并发数
返回 NonZeroU64
作为并发数类型。
Examples found in repository?
src/data_partition_provider/mod.rs (line 52)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
pub fn as_u64(&self) -> u64 {
self.as_non_zero_u64().get()
}
}
impl Default for PartSize {
#[inline]
fn default() -> Self {
Self(
#[allow(unsafe_code)]
unsafe {
NonZeroU64::new_unchecked(1 << 22)
},
)
}
}
impl From<NonZeroU64> for PartSize {
#[inline]
fn from(size: NonZeroU64) -> Self {
Self(size)
}
}
impl From<PartSize> for NonZeroU64 {
#[inline]
fn from(size: PartSize) -> Self {
size.as_non_zero_u64()
}
More examples
sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
获取并发数
Examples found in repository?
More examples
src/data_source/seekable.rs (line 44)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn slice(&self, size: PartSize) -> IoResult<Option<DataSourceReader>> {
let mut cur = self.current.lock().unwrap();
if cur.offset < self.size {
let size = size.as_u64();
let source_reader = DataSourceReader::seekable(
cur.part_number,
self.source.clone_with_new_offset_and_length(cur.offset, size),
);
cur.offset += size;
cur.part_number = NonZeroUsize::new(cur.part_number.get() + 1).expect("Page number is too big");
Ok(Some(source_reader))
} else {
Ok(None)
}
}
src/data_source/unseekable.rs (line 55)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
fn slice(&self, size: PartSize) -> IoResult<Option<DataSourceReader>> {
let mut buf = Vec::new();
let guard = &mut self.0.lock().unwrap();
let have_read = (&mut guard.reader).take(size.as_u64()).read_to_end(&mut buf)?;
if have_read > 0 {
let source_reader = DataSourceReader::unseekable(guard.current_part_number, buf, guard.current_offset);
guard.current_offset += have_read as u64;
guard.current_part_number =
NonZeroUsize::new(guard.current_part_number.get() + 1).expect("Page number is too big");
Ok(Some(source_reader))
} else {
Ok(None)
}
}
#[inline]
fn reset(&self) -> IoResult<()> {
Err(unsupported_reset_error())
}
#[inline]
fn source_key(&self) -> IoResult<Option<SourceKey<A>>> {
Ok(self.0.lock().unwrap().source_key.to_owned())
}
#[inline]
fn total_size(&self) -> IoResult<Option<u64>> {
Ok(None)
}
}
impl<R: Read + Debug + Send + Sync + 'static, A: Digest> Debug for UnseekableDataSourceInner<R, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("UnseekableDataSourceInner")
.field("reader", &self.reader)
.field("current_offset", &self.current_offset)
.field("current_part_number", &self.current_part_number)
.field("source_key", &self.source_key)
.finish()
}
}
#[cfg(feature = "async")]
mod async_unseekable {
use super::{
super::{AsyncDataSource, AsyncDataSourceReader},
*,
};
use futures::{
future::{self, BoxFuture},
lock::Mutex,
AsyncRead, AsyncReadExt,
};
/// 不可寻址的异步数据源
///
/// 基于一个不可寻址的异步阅读器实现了异步数据源接口
pub struct AsyncUnseekableDataSource<R: AsyncRead + Debug + Unpin + Send + Sync + 'static + ?Sized, A: Digest = Sha1>(
Arc<Mutex<AsyncUnseekableDataSourceInner<R, A>>>,
);
impl<R: AsyncRead + Debug + Unpin + Send + Sync + 'static, A: Digest> Debug for AsyncUnseekableDataSource<R, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("AsyncUnseekableDataSource").field(&self.0).finish()
}
}
impl<R: AsyncRead + Debug + Unpin + Send + Sync + 'static, A: Digest> Clone for AsyncUnseekableDataSource<R, A> {
#[inline]
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
struct AsyncUnseekableDataSourceInner<R: AsyncRead + Debug + Unpin + Send + Sync + 'static + ?Sized, A: Digest> {
current_offset: u64,
current_part_number: NonZeroUsize,
source_key: Option<SourceKey<A>>,
reader: R,
}
impl<R: AsyncRead + Debug + Unpin + Send + Sync + 'static, A: Digest> AsyncUnseekableDataSource<R, A> {
/// 创建不可寻址的异步数据源
pub fn new(reader: R) -> Self {
Self(Arc::new(Mutex::new(AsyncUnseekableDataSourceInner {
reader,
current_offset: 0,
current_part_number: first_part_number(),
source_key: None,
})))
}
}
impl<R: AsyncRead + Debug + Unpin + Send + Sync + 'static, A: Digest> AsyncDataSource<A>
for AsyncUnseekableDataSource<R, A>
{
fn slice(&self, size: PartSize) -> BoxFuture<IoResult<Option<AsyncDataSourceReader>>> {
Box::pin(async move {
let mut buf = Vec::new();
let guard = &mut self.0.lock().await;
let have_read = (&mut guard.reader).take(size.as_u64()).read_to_end(&mut buf).await?;
if have_read > 0 {
let source_reader =
AsyncDataSourceReader::unseekable(guard.current_part_number, buf, guard.current_offset);
guard.current_offset += have_read as u64;
guard.current_part_number =
NonZeroUsize::new(guard.current_part_number.get() + 1).expect("Page number is too big");
Ok(Some(source_reader))
} else {
Ok(None)
}
})
}
src/data_source/file.rs (line 196)
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
fn slice(&self, size: PartSize) -> BoxFuture<IoResult<Option<AsyncDataSourceReader>>> {
Box::pin(async move {
match self.get_async_seekable_source().await? {
AsyncSource::Seekable {
source,
current,
file_size,
..
} => {
let mut cur = current.lock().await;
if cur.offset < *file_size {
let size = size.as_u64();
let source_reader = AsyncDataSourceReader::seekable(
cur.part_number,
source.clone_with_new_offset_and_length(cur.offset, size),
);
cur.offset += size;
cur.part_number =
NonZeroUsize::new(cur.part_number.get() + 1).expect("Page number is too big");
Ok(Some(source_reader))
} else {
Ok(None)
}
}
AsyncSource::Unseekable(source) => source.slice(size).await,
}
})
}
Methods from Deref<Target = NonZeroU64>§
pub const MIN: NonZeroU64 = Self::new(1).unwrap()
pub const MAX: NonZeroU64 = Self::new(u64::MAX).unwrap()
Trait Implementations§
source§impl From<NonZeroU64> for PartSize
impl From<NonZeroU64> for PartSize
source§fn from(size: NonZeroU64) -> Self
fn from(size: NonZeroU64) -> Self
Converts to this type from the input type.
source§impl From<PartSize> for NonZeroU64
impl From<PartSize> for NonZeroU64
source§impl Ord for PartSize
impl Ord for PartSize
source§impl PartialEq<PartSize> for PartSize
impl PartialEq<PartSize> for PartSize
source§impl PartialOrd<PartSize> for PartSize
impl PartialOrd<PartSize> for PartSize
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for PartSize
impl Eq for PartSize
impl StructuralEq for PartSize
impl StructuralPartialEq for PartSize
Auto Trait Implementations§
impl RefUnwindSafe for PartSize
impl Send for PartSize
impl Sync for PartSize
impl Unpin for PartSize
impl UnwindSafe for PartSize
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows
self
, then passes self.as_mut()
into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Immutable access to the
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Immutable access to the
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Mutable access to the
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Calls
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.