Skip to content

Commit 0426f34

Browse files
authored
feat(ipld): undeprecate for_each methods for hamt/kamt (#2080)
These are useful because they handle some error cases and the ranged version is especially useful as using iter + skip etc. is actually kind of annoying. It would still be better to replace these with iterators in many cases, but replacing them _everywhere_ is annoying and not worth the effort.
1 parent d76ae62 commit 0426f34

File tree

5 files changed

+0
-19
lines changed

5 files changed

+0
-19
lines changed

ipld/amt/benches/amt_benchmark.rs

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ fn for_each(c: &mut Criterion) {
123123
c.bench_function("AMT for_each function", |b| {
124124
b.iter(|| {
125125
let a = Amt::load(&cid, &db).unwrap();
126-
#[allow(deprecated)]
127126
black_box(a).for_each(|_, _v: &u64| Ok(())).unwrap();
128127
})
129128
});

ipld/amt/src/amt.rs

-4
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ where
448448
/// assert_eq!(&values, &[(1, "One".to_owned()), (4, "Four".to_owned())]);
449449
/// ```
450450
#[inline]
451-
#[deprecated = "use `.iter()` instead"]
452451
pub fn for_each<F>(&self, mut f: F) -> Result<(), Error>
453452
where
454453
F: FnMut(u64, &V) -> anyhow::Result<()>,
@@ -462,7 +461,6 @@ where
462461

463462
/// Iterates over each value in the Amt and runs a function on the values, for as long as that
464463
/// function keeps returning `true`.
465-
#[deprecated = "use `.iter()` instead"]
466464
pub fn for_each_while<F>(&self, mut f: F) -> Result<(), Error>
467465
where
468466
F: FnMut(u64, &V) -> anyhow::Result<bool>,
@@ -508,7 +506,6 @@ where
508506
/// assert_eq!(num_traversed, 3);
509507
/// assert_eq!(next_idx, Some(10));
510508
/// ```
511-
#[deprecated = "use `.iter_from()` and `.take(limit)` instead"]
512509
pub fn for_each_ranged<F>(
513510
&self,
514511
start_at: Option<u64>,
@@ -539,7 +536,6 @@ where
539536
/// `limit` elements have been traversed. Returns a tuple describing the number of elements
540537
/// iterated over and optionally the index of the next element in the AMT if more elements
541538
/// remain.
542-
#[deprecated = "use `.iter_from()` and `.take(limit)` instead"]
543539
pub fn for_each_while_ranged<F>(
544540
&self,
545541
start_at: Option<u64>,

ipld/amt/src/iter.rs

-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ mod tests {
343343
let k = Amt::<&str, _>::new_from_iter(&mem, data.iter().map(|s| &**s)).unwrap();
344344
let a: Amt<String, _> = Amt::load(&k, &mem).unwrap();
345345
let mut restored = Vec::new();
346-
#[allow(deprecated)]
347346
a.for_each(|k, v| {
348347
restored.push((k as usize, v.clone()));
349348
Ok(())
@@ -381,7 +380,6 @@ mod tests {
381380
let new_amt = Amt::load(&c, &db).unwrap();
382381

383382
let mut x = 0;
384-
#[allow(deprecated)]
385383
new_amt
386384
.for_each(|k, _: &BytesDe| {
387385
if k != indexes[x] {

ipld/amt/tests/amt_tests.rs

-11
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ fn for_each() {
352352

353353
// Iterate over amt with dirty cache
354354
let mut x = 0;
355-
#[allow(deprecated)]
356355
a.for_each(|_, _: &BytesDe| {
357356
x += 1;
358357
Ok(())
@@ -367,7 +366,6 @@ fn for_each() {
367366
assert_eq!(new_amt.count(), indexes.len() as u64);
368367

369368
let mut x = 0;
370-
#[allow(deprecated)]
371369
new_amt
372370
.for_each(|i, _: &BytesDe| {
373371
if i != indexes[x] {
@@ -382,7 +380,6 @@ fn for_each() {
382380
.unwrap();
383381
assert_eq!(x, indexes.len());
384382

385-
#[allow(deprecated)]
386383
new_amt.for_each(|_, _: &BytesDe| Ok(())).unwrap();
387384
assert_eq!(
388385
c.to_string().as_str(),
@@ -420,7 +417,6 @@ fn for_each_ranged() {
420417
// Iterate over amt with dirty cache from different starting values
421418
for start_val in 0..RANGE {
422419
let mut retrieved_values = Vec::new();
423-
#[allow(deprecated)]
424420
let (count, next_key) = a
425421
.for_each_while_ranged(Some(start_val), None, |index, _: &BytesDe| {
426422
retrieved_values.push(index);
@@ -436,7 +432,6 @@ fn for_each_ranged() {
436432

437433
// Iterate out of bounds
438434
for i in [RANGE, RANGE + 1, 2 * RANGE, 8 * RANGE] {
439-
#[allow(deprecated)]
440435
let (count, next_key) = a
441436
.for_each_while_ranged(Some(i), None, |_, _: &BytesDe| {
442437
panic!("didn't expect to iterate")
@@ -449,7 +444,6 @@ fn for_each_ranged() {
449444
// Iterate over amt with dirty cache with different page sizes
450445
for page_size in 1..=RANGE {
451446
let mut retrieved_values = Vec::new();
452-
#[allow(deprecated)]
453447
let (count, next_key) = a
454448
.for_each_while_ranged(None, Some(page_size), |index, _: &BytesDe| {
455449
retrieved_values.push(index);
@@ -471,7 +465,6 @@ fn for_each_ranged() {
471465
let mut retrieved_values = Vec::new();
472466
let mut start_cursor = None;
473467
loop {
474-
#[allow(deprecated)]
475468
let (num_traversed, next_cursor) = a
476469
.for_each_while_ranged(start_cursor, Some(page_size), |idx, _val| {
477470
retrieved_values.push(idx);
@@ -497,7 +490,6 @@ fn for_each_ranged() {
497490
let mut retrieved_values = Vec::new();
498491
let mut start_cursor = None;
499492
loop {
500-
#[allow(deprecated)]
501493
let (num_traversed, next_cursor) = a
502494
.for_each_ranged(start_cursor, Some(page_size), |idx, _val: &BytesDe| {
503495
retrieved_values.push(idx);
@@ -523,7 +515,6 @@ fn for_each_ranged() {
523515

524516
// Iterate over the amt with dirty cache ignoring gaps in the address space including at the
525517
// beginning of the amt, we should only see the values that were not deleted
526-
#[allow(deprecated)]
527518
let (num_traversed, next_cursor) = a
528519
.for_each_while_ranged(Some(0), Some(501), |i, _v| {
529520
assert_eq!((i / 10) % 2, 1); // only "odd" batches of ten 10 - 19, 30 - 39, etc. should be present
@@ -536,7 +527,6 @@ fn for_each_ranged() {
536527
// flush the amt to the blockstore, reload and repeat the test with a clean cache
537528
let cid = a.flush().unwrap();
538529
let a = Amt::load(&cid, &db).unwrap();
539-
#[allow(deprecated)]
540530
let (num_traversed, next_cursor) = a
541531
.for_each_while_ranged(Some(0), Some(501), |i, _v: &BytesDe| {
542532
assert_eq!((i / 10) % 2, 1); // only "odd" batches of ten 10 - 19, 30 - 39, etc. should be present
@@ -632,7 +622,6 @@ fn new_from_iter() {
632622

633623
let a: Amt<String, _> = Amt::load(&k, &mem).unwrap();
634624
let mut restored = Vec::new();
635-
#[allow(deprecated)]
636625
a.for_each(|k, v| {
637626
restored.push((k as usize, v.clone()));
638627
Ok(())

ipld/kamt/src/kamt.rs

-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ where
339339
/// assert_eq!(total, 3);
340340
/// ```
341341
#[inline]
342-
#[deprecated = "use `.iter()` instead"]
343342
pub fn for_each<F>(&self, mut f: F) -> Result<(), Error>
344343
where
345344
V: DeserializeOwned,

0 commit comments

Comments
 (0)