Skip to content

Commit e4f542b

Browse files
migrate from failure to anyhow + thiserror (#127)
1 parent 34a1694 commit e4f542b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+861
-429
lines changed

bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Benchmarks for Capsule.
1010
"""
1111

1212
[dev-dependencies]
13+
anyhow = "1.0"
1314
capsule = { version = "0.1", path = "../core", features = ["testils"] }
1415
criterion = "0.3"
15-
failure = "0.1"
1616
proptest = "0.10"
1717

1818
[[bench]]

bench/combinators.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
use anyhow::Result;
1920
use capsule::batch::{Batch, Either};
2021
use capsule::packets::ip::v4::Ipv4;
2122
use capsule::packets::{Ethernet, Packet};
2223
use capsule::testils::criterion::BencherExt;
2324
use capsule::testils::proptest::*;
2425
use capsule::{compose, Mbuf};
2526
use criterion::{criterion_group, criterion_main, Criterion};
26-
use failure::Fallible;
2727
use proptest::prelude::*;
2828
use proptest::strategy;
2929

@@ -86,7 +86,7 @@ fn map(batch: impl Batch<Item = Mbuf>) -> impl Batch<Item = Ethernet> {
8686
batch.map(|p| p.parse::<Ethernet>())
8787
}
8888

89-
fn no_batch_map(mbuf: Mbuf) -> Fallible<Ethernet> {
89+
fn no_batch_map(mbuf: Mbuf) -> Result<Ethernet> {
9090
mbuf.parse::<Ethernet>()
9191
}
9292

@@ -189,7 +189,7 @@ fn replace(batch: impl Batch<Item = Mbuf>) -> impl Batch<Item = Mbuf> {
189189
batch.replace(|_p| Mbuf::new())
190190
}
191191

192-
fn no_batch_replace(_mbuf: Mbuf) -> Fallible<Mbuf> {
192+
fn no_batch_replace(_mbuf: Mbuf) -> Result<Mbuf> {
193193
Mbuf::new()
194194
}
195195

bench/mbuf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
use anyhow::Result;
1920
use capsule::Mbuf;
2021
use criterion::{criterion_group, criterion_main, Criterion};
21-
use failure::Fallible;
2222

2323
const BATCH_SIZE: usize = 100;
2424

25-
fn alloc() -> Fallible<Vec<Mbuf>> {
25+
fn alloc() -> Result<Vec<Mbuf>> {
2626
(0..BATCH_SIZE)
2727
.map(|_| Mbuf::new())
28-
.collect::<Fallible<Vec<Mbuf>>>()
28+
.collect::<Result<Vec<Mbuf>>>()
2929
}
3030

31-
fn alloc_bulk() -> Fallible<Vec<Mbuf>> {
31+
fn alloc_bulk() -> Result<Vec<Mbuf>> {
3232
Mbuf::alloc_bulk(BATCH_SIZE)
3333
}
3434

bench/packets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19+
use anyhow::Result;
1920
use capsule::packets::ip::v4::Ipv4;
2021
use capsule::packets::ip::v6::{Ipv6, SegmentRouting};
2122
use capsule::packets::{Ethernet, Packet, Udp4};
@@ -24,7 +25,6 @@ use capsule::testils::proptest::*;
2425
use capsule::testils::{PacketExt, Rvg};
2526
use capsule::{fieldmap, Mbuf};
2627
use criterion::{criterion_group, criterion_main, Criterion};
27-
use failure::Fallible;
2828
use proptest::prelude::*;
2929
use std::net::Ipv6Addr;
3030

@@ -228,7 +228,7 @@ fn multi_remove(c: &mut Criterion) {
228228
});
229229
}
230230

231-
fn set_srh_segments(mut args: (SegmentRouting<Ipv6>, Vec<Ipv6Addr>)) -> Fallible<()> {
231+
fn set_srh_segments(mut args: (SegmentRouting<Ipv6>, Vec<Ipv6Addr>)) -> Result<()> {
232232
args.0.set_segments(&args.1)
233233
}
234234

core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ path = "src/lib.rs"
2020
doctest = false
2121

2222
[dependencies]
23+
anyhow = "1.0"
2324
capsule-ffi = { version = "0.1.4", path = "../ffi" }
2425
capsule-macros = { version = "0.1.4", path = "../macros" }
2526
clap = "2.33"
2627
criterion = { version = "0.3", optional = true }
27-
failure = "0.1"
2828
futures-preview = "=0.3.0-alpha.19"
2929
libc = "0.2"
3030
metrics-core = { version = "0.5", optional = true }
@@ -33,6 +33,7 @@ once_cell = "1.2"
3333
proptest = { version = "0.10", optional = true }
3434
regex = "1"
3535
serde = { version = "1.0", features = ["derive"] }
36+
thiserror = "1.0"
3637
tokio = "=0.2.0-alpha.6"
3738
tokio-executor = { version = "=0.2.0-alpha.6", features = ["current-thread", "threadpool"] }
3839
tokio-net = { version = "=0.2.0-alpha.6", features = ["signal"] }

core/src/batch/filter_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use super::{Batch, Disposition};
2020
use crate::packets::Packet;
2121
use crate::Mbuf;
22-
use failure::Fallible;
22+
use anyhow::Result;
2323

2424
/// The result of a [`filter_map`].
2525
///
@@ -41,15 +41,15 @@ pub enum Either<T> {
4141
#[allow(missing_debug_implementations)]
4242
pub struct FilterMap<B: Batch, T: Packet, F>
4343
where
44-
F: FnMut(B::Item) -> Fallible<Either<T>>,
44+
F: FnMut(B::Item) -> Result<Either<T>>,
4545
{
4646
batch: B,
4747
f: F,
4848
}
4949

5050
impl<B: Batch, T: Packet, F> FilterMap<B, T, F>
5151
where
52-
F: FnMut(B::Item) -> Fallible<Either<T>>,
52+
F: FnMut(B::Item) -> Result<Either<T>>,
5353
{
5454
/// Creates a new `FilterMap` batch.
5555
#[inline]
@@ -60,7 +60,7 @@ where
6060

6161
impl<B: Batch, T: Packet, F> Batch for FilterMap<B, T, F>
6262
where
63-
F: FnMut(B::Item) -> Fallible<Either<T>>,
63+
F: FnMut(B::Item) -> Result<Either<T>>,
6464
{
6565
type Item = T;
6666

core/src/batch/for_each.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
*/
1818

1919
use super::{Batch, Disposition};
20-
use failure::Fallible;
20+
use anyhow::Result;
2121

2222
/// A batch that calls a closure on packets in the underlying batch.
2323
#[allow(missing_debug_implementations)]
2424
pub struct ForEach<B: Batch, F>
2525
where
26-
F: FnMut(&B::Item) -> Fallible<()>,
26+
F: FnMut(&B::Item) -> Result<()>,
2727
{
2828
batch: B,
2929
f: F,
3030
}
3131

3232
impl<B: Batch, F> ForEach<B, F>
3333
where
34-
F: FnMut(&B::Item) -> Fallible<()>,
34+
F: FnMut(&B::Item) -> Result<()>,
3535
{
3636
/// Creates a new `ForEach` batch.
3737
#[inline]
@@ -42,7 +42,7 @@ where
4242

4343
impl<B: Batch, F> Batch for ForEach<B, F>
4444
where
45-
F: FnMut(&B::Item) -> Fallible<()>,
45+
F: FnMut(&B::Item) -> Result<()>,
4646
{
4747
type Item = B::Item;
4848

core/src/batch/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use super::{Batch, Disposition};
2020
use crate::packets::Packet;
21-
use failure::Fallible;
21+
use anyhow::Result;
2222

2323
/// A batch that maps the packets of the underlying batch.
2424
///
@@ -27,15 +27,15 @@ use failure::Fallible;
2727
#[allow(missing_debug_implementations)]
2828
pub struct Map<B: Batch, T: Packet, F>
2929
where
30-
F: FnMut(B::Item) -> Fallible<T>,
30+
F: FnMut(B::Item) -> Result<T>,
3131
{
3232
batch: B,
3333
f: F,
3434
}
3535

3636
impl<B: Batch, T: Packet, F> Map<B, T, F>
3737
where
38-
F: FnMut(B::Item) -> Fallible<T>,
38+
F: FnMut(B::Item) -> Result<T>,
3939
{
4040
/// Creates a new `Map` batch.
4141
#[inline]
@@ -46,7 +46,7 @@ where
4646

4747
impl<B: Batch, T: Packet, F> Batch for Map<B, T, F>
4848
where
49-
F: FnMut(B::Item) -> Fallible<T>,
49+
F: FnMut(B::Item) -> Result<T>,
5050
{
5151
type Item = T;
5252

core/src/batch/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use self::send::*;
4444

4545
use crate::packets::Packet;
4646
use crate::Mbuf;
47-
use failure::{Error, Fallible};
47+
use anyhow::{Error, Result};
4848
use std::collections::HashMap;
4949
use std::hash::Hash;
5050

@@ -198,7 +198,7 @@ pub trait Batch {
198198
#[inline]
199199
fn filter_map<T: Packet, F>(self, f: F) -> FilterMap<Self, T, F>
200200
where
201-
F: FnMut(Self::Item) -> Fallible<Either<T>>,
201+
F: FnMut(Self::Item) -> Result<Either<T>>,
202202
Self: Sized,
203203
{
204204
FilterMap::new(self, f)
@@ -216,7 +216,7 @@ pub trait Batch {
216216
#[inline]
217217
fn map<T: Packet, F>(self, f: F) -> Map<Self, T, F>
218218
where
219-
F: FnMut(Self::Item) -> Fallible<T>,
219+
F: FnMut(Self::Item) -> Result<T>,
220220
Self: Sized,
221221
{
222222
Map::new(self, f)
@@ -238,7 +238,7 @@ pub trait Batch {
238238
#[inline]
239239
fn for_each<F>(self, f: F) -> ForEach<Self, F>
240240
where
241-
F: FnMut(&Self::Item) -> Fallible<()>,
241+
F: FnMut(&Self::Item) -> Result<()>,
242242
Self: Sized,
243243
{
244244
ForEach::new(self, f)
@@ -343,7 +343,7 @@ pub trait Batch {
343343
/// });
344344
fn replace<T: Packet, F>(self, f: F) -> Replace<Self, T, F>
345345
where
346-
F: FnMut(&Self::Item) -> Fallible<T>,
346+
F: FnMut(&Self::Item) -> Result<T>,
347347
Self: Sized,
348348
{
349349
Replace::new(self, f)

core/src/batch/replace.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
use super::{Batch, Disposition};
2020
use crate::packets::Packet;
21-
use failure::Fallible;
21+
use anyhow::Result;
2222

2323
/// A batch that replaces each packet of the batch with another packet.
2424
///
@@ -28,7 +28,7 @@ use failure::Fallible;
2828
#[allow(missing_debug_implementations)]
2929
pub struct Replace<B: Batch, T: Packet, F>
3030
where
31-
F: FnMut(&B::Item) -> Fallible<T>,
31+
F: FnMut(&B::Item) -> Result<T>,
3232
{
3333
batch: B,
3434
f: F,
@@ -37,7 +37,7 @@ where
3737

3838
impl<B: Batch, T: Packet, F> Replace<B, T, F>
3939
where
40-
F: FnMut(&B::Item) -> Fallible<T>,
40+
F: FnMut(&B::Item) -> Result<T>,
4141
{
4242
/// Creates a new `Replace` batch.
4343
#[inline]
@@ -52,7 +52,7 @@ where
5252

5353
impl<B: Batch, T: Packet, F> Batch for Replace<B, T, F>
5454
where
55-
F: FnMut(&B::Item) -> Fallible<T>,
55+
F: FnMut(&B::Item) -> Result<T>,
5656
{
5757
type Item = T;
5858

0 commit comments

Comments
 (0)