Skip to content

Commit 5b3a9bf

Browse files
ref(chunks): Use NonZeroUsize in Chunked type
This allows us to avoid returning `Result` in `Chunked::from`.
1 parent 3d82836 commit 5b3a9bf

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/commands/dart_symbol_map/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub(super) fn execute(args: DartSymbolMapUploadArgs) -> Result<()> {
159159
let options = ChunkOptions::new(chunk_upload_options, org, project)
160160
.with_max_wait(DEFAULT_MAX_WAIT);
161161

162-
let chunked = Chunked::from(object, options.server_options().chunk_size as usize)?;
162+
let chunked = Chunked::from(object, (options.server_options().chunk_size as usize).try_into()?);
163163
let (_uploaded, has_processing_errors) = upload_chunked_objects(&[chunked], options)?;
164164
if has_processing_errors {
165165
bail!("Some symbol maps did not process correctly");

src/utils/chunks/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use std::borrow::Cow;
44
use std::fmt::{Display, Formatter, Result as FmtResult};
5+
use std::num::NonZeroUsize;
56

6-
use anyhow::Result;
77
use sha1_smol::Digest;
88
use symbolic::common::DebugId;
99

@@ -37,7 +37,7 @@ pub struct Chunked<T> {
3737
chunks: Vec<Digest>,
3838

3939
/// Size of a single chunk
40-
chunk_size: usize,
40+
chunk_size: NonZeroUsize,
4141
}
4242

4343
impl<T> Chunked<T> {
@@ -63,14 +63,14 @@ where
6363
{
6464
/// Creates a new `ChunkedObject` from the given object, using
6565
/// the given chunk size.
66-
pub fn from(object: T, chunk_size: usize) -> Result<Self> {
67-
let (checksum, chunks) = fs::get_sha1_checksums(object.as_ref(), chunk_size.try_into()?);
68-
Ok(Self {
66+
pub fn from(object: T, chunk_size: NonZeroUsize) -> Self {
67+
let (checksum, chunks) = fs::get_sha1_checksums(object.as_ref(), chunk_size);
68+
Self {
6969
object,
7070
checksum,
7171
chunks,
7272
chunk_size,
73-
})
73+
}
7474
}
7575

7676
/// Returns an iterator over all chunks of the object.
@@ -79,7 +79,7 @@ where
7979
pub fn iter_chunks(&self) -> impl Iterator<Item = Chunk<'_>> {
8080
self.object
8181
.as_ref()
82-
.chunks(self.chunk_size)
82+
.chunks(self.chunk_size.into())
8383
.zip(self.chunk_hashes().iter())
8484
.map(|(data, checksum)| Chunk((*checksum, data)))
8585
}

src/utils/dif_upload/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,10 @@ fn upload_difs_chunked(
12361236
processed.extend(source_bundles);
12371237
}
12381238

1239+
let chunk_size = (chunk_options.chunk_size as usize).try_into()?;
1240+
12391241
// Calculate checksums and chunks
1240-
let chunked = prepare_difs(processed, |m| {
1241-
Chunked::from(m, chunk_options.chunk_size as usize)
1242-
})?;
1242+
let chunked = prepare_difs(processed, |m| Ok(Chunked::from(m, chunk_size)))?;
12431243

12441244
if options.no_upload {
12451245
println!("{} skipping upload.", style(">").dim());

src/utils/proguard/upload.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ pub fn chunk_upload(
2626
org: &str,
2727
project: &str,
2828
) -> Result<()> {
29+
let chunk_size = (chunk_upload_options.chunk_size as usize).try_into()?;
2930
let chunked_mappings = mappings
3031
.iter()
31-
.map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize))
32-
.collect::<Result<Vec<_>>>()?;
32+
.map(|mapping| Chunked::from(mapping, chunk_size))
33+
.collect::<Vec<_>>();
3334

3435
let options =
3536
ChunkOptions::new(chunk_upload_options, org, project).with_max_wait(ASSEMBLE_POLL_TIMEOUT);

0 commit comments

Comments
 (0)