Skip to content

Commit 7c57cf1

Browse files
Move to Rust 1.50 (#129)
- includes new lines associated w/ - https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps - https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention - updates bindings file in preparation for release. - associated pr will be pushed to sandbox once this is in.
1 parent 8dd1dd9 commit 7c57cf1

File tree

17 files changed

+242
-258
lines changed

17 files changed

+242
-258
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The easiest way to start developing `Capsule` applications is to use the `Vagran
5050

5151
- [`DPDK` 19.11](https://doc.dpdk.org/guides-19.11/rel_notes/release_19_11.html)
5252
- [`Clang`](https://clang.llvm.org/) and [`LLVM`](https://www.llvm.org/)
53-
- [`Rust 1.49`](https://blog.rust-lang.org/2020/12/31/Rust-1.49.0.html)
53+
- [`Rust 1.50`](https://blog.rust-lang.org/2021/02/11/Rust-1.50.0.html)
5454
- [`rr`](https://rr-project.org/) 5.3
5555

5656
First install [`Vagrant`](https://www.vagrantup.com/) and [`VirtualBox`](https://www.virtualbox.org/) on your system. Also install the following `Vagrant` plugins,
@@ -79,7 +79,7 @@ vagrant$ docker run -it --rm \
7979
--security-opt seccomp=unconfined \
8080
-v /lib/modules:/lib/modules \
8181
-v /dev/hugepages:/dev/hugepages \
82-
getcapsule/sandbox:19.11.6-1.49 /bin/bash
82+
getcapsule/sandbox:19.11.6-1.50 /bin/bash
8383
```
8484

8585
Remember to also mount the working directory of your project as a volume for the sandbox. Then you can use `Cargo` commands inside the container as normal.
@@ -103,7 +103,7 @@ This project and everyone participating in it are governed by the [Capsule Code
103103

104104
## Contact
105105

106-
You can contact us either through [`Discord`](https://discord.gg/sVN47RU) or [email](mailto:[email protected]).
106+
You can contact us either through [`Discord`](https://discord.gg/sAgzNV27sA) or [email](mailto:[email protected]).
107107

108108
## Maintainers
109109

bench/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Benchmarks for Capsule.
1313
anyhow = "1.0"
1414
capsule = { version = "0.1", path = "../core", features = ["testils"] }
1515
criterion = "0.3"
16-
proptest = "0.10"
16+
proptest = "1.0"
1717

1818
[[bench]]
1919
name = "packets"

core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ futures-preview = "=0.3.0-alpha.19"
2929
libc = "0.2"
3030
metrics-core = { version = "0.5", optional = true }
3131
metrics-runtime = { version = "0.13", optional = true, default-features = false }
32-
once_cell = "1.2"
33-
proptest = { version = "0.10", optional = true }
32+
once_cell = "1.7"
33+
proptest = { version = "1.0", optional = true }
3434
regex = "1"
3535
serde = { version = "1.0", features = ["derive"] }
3636
thiserror = "1.0"
@@ -43,7 +43,7 @@ tracing = "0.1"
4343

4444
[dev-dependencies]
4545
criterion = "0.3"
46-
proptest = { version = "0.10", default-features = false, features = ["default-code-coverage"] }
46+
proptest = { version = "1.0", default-features = false, features = ["default-code-coverage"] }
4747

4848
[features]
4949
default = ["metrics"]

core/src/dpdk/kni.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl KniRx {
101101
unsafe {
102102
// checks if there are any link change requests, and handle them.
103103
if let Err(err) =
104-
ffi::rte_kni_handle_request(self.raw.as_mut()).to_result(|_| DpdkError::new())
104+
ffi::rte_kni_handle_request(self.raw.as_mut()).into_result(|_| DpdkError::new())
105105
{
106106
warn!(message = "failed to handle change link requests.", ?err);
107107
}
@@ -304,7 +304,7 @@ impl Drop for Kni {
304304
debug!("freeing kernel interface.");
305305

306306
if let Err(err) =
307-
unsafe { ffi::rte_kni_release(self.raw_mut()).to_result(|_| DpdkError::new()) }
307+
unsafe { ffi::rte_kni_release(self.raw_mut()).into_result(|_| DpdkError::new()) }
308308
{
309309
error!(message = "failed to release KNI device.", ?err);
310310
}
@@ -388,7 +388,7 @@ impl<'a> KniBuilder<'a> {
388388

389389
unsafe {
390390
ffi::rte_kni_alloc(self.mempool, &self.conf, &mut self.ops)
391-
.to_result(|_| DpdkError::new())
391+
.into_result(|_| DpdkError::new())
392392
.map(Kni::new)
393393
}
394394
}
@@ -398,7 +398,7 @@ impl<'a> KniBuilder<'a> {
398398
pub(crate) fn kni_init(max: usize) -> Result<()> {
399399
unsafe {
400400
ffi::rte_kni_init(max as raw::c_uint)
401-
.to_result(DpdkError::from_errno)
401+
.into_result(DpdkError::from_errno)
402402
.map(|_| ())
403403
}
404404
}

core/src/dpdk/mbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Mbuf {
149149
pub fn new() -> Result<Self> {
150150
let mempool = MEMPOOL.with(|tls| tls.get());
151151
let raw =
152-
unsafe { ffi::_rte_pktmbuf_alloc(mempool).to_result(|_| MempoolError::Exhausted)? };
152+
unsafe { ffi::_rte_pktmbuf_alloc(mempool).into_result(|_| MempoolError::Exhausted)? };
153153

154154
Ok(Mbuf {
155155
inner: MbufInner::Original(raw),
@@ -434,7 +434,7 @@ impl Mbuf {
434434

435435
let mbufs = unsafe {
436436
ffi::_rte_pktmbuf_alloc_bulk(mempool, ptrs.as_mut_ptr(), len as raw::c_uint)
437-
.to_result(DpdkError::from_errno)?;
437+
.into_result(DpdkError::from_errno)?;
438438

439439
ptrs.set_len(len);
440440
ptrs.into_iter()

core/src/dpdk/mempool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ impl Mempool {
5959

6060
let raw = unsafe {
6161
ffi::rte_pktmbuf_pool_create(
62-
name.clone().to_cstring().as_ptr(),
62+
name.clone().into_cstring().as_ptr(),
6363
capacity as raw::c_uint,
6464
cache_size as raw::c_uint,
6565
0,
6666
ffi::RTE_MBUF_DEFAULT_BUF_SIZE as u16,
6767
socket_id.raw(),
6868
)
69-
.to_result(|_| DpdkError::new())?
69+
.into_result(|_| DpdkError::new())?
7070
};
7171

7272
info!("created {}.", name);

core/src/dpdk/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl CoreId {
159159
let mut set: libc::cpu_set_t = mem::zeroed();
160160
libc::CPU_SET(self.0, &mut set);
161161
let mut set: ffi::rte_cpuset_t = mem::transmute(set);
162-
ffi::rte_thread_set_affinity(&mut set).to_result(DpdkError::from_errno)?;
162+
ffi::rte_thread_set_affinity(&mut set).into_result(DpdkError::from_errno)?;
163163
}
164164

165165
CURRENT_CORE_ID.with(|tls| tls.set(*self));
@@ -182,7 +182,10 @@ pub(crate) fn eal_init(args: Vec<String>) -> Result<()> {
182182
debug!(arguments=?args);
183183

184184
let len = args.len() as raw::c_int;
185-
let args = args.into_iter().map(|s| s.to_cstring()).collect::<Vec<_>>();
185+
let args = args
186+
.into_iter()
187+
.map(|s| s.into_cstring())
188+
.collect::<Vec<_>>();
186189
let mut ptrs = args
187190
.iter()
188191
.map(|s| s.as_ptr() as *mut raw::c_char)
@@ -191,14 +194,14 @@ pub(crate) fn eal_init(args: Vec<String>) -> Result<()> {
191194
let res = unsafe { ffi::rte_eal_init(len, ptrs.as_mut_ptr()) };
192195
debug!("EAL parsed {} arguments.", res);
193196

194-
res.to_result(DpdkError::from_errno).map(|_| ())
197+
res.into_result(DpdkError::from_errno).map(|_| ())
195198
}
196199

197200
/// Cleans up the Environment Abstraction Layer (EAL).
198201
pub(crate) fn eal_cleanup() -> Result<()> {
199202
unsafe {
200203
ffi::rte_eal_cleanup()
201-
.to_result(DpdkError::from_errno)
204+
.into_result(DpdkError::from_errno)
202205
.map(|_| ())
203206
}
204207
}

core/src/dpdk/port.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl Port {
326326
/// If the port fails to start, `DpdkError` is returned.
327327
pub(crate) fn start(&mut self) -> Result<()> {
328328
unsafe {
329-
ffi::rte_eth_dev_start(self.id.0).to_result(DpdkError::from_errno)?;
329+
ffi::rte_eth_dev_start(self.id.0).into_result(DpdkError::from_errno)?;
330330
}
331331

332332
info!("started port {}.", self.name());
@@ -400,8 +400,8 @@ impl<'a> PortBuilder<'a> {
400400
pub(crate) fn new(name: String, device: String) -> Result<Self> {
401401
let mut port_id = 0u16;
402402
unsafe {
403-
ffi::rte_eth_dev_get_port_by_name(device.clone().to_cstring().as_ptr(), &mut port_id)
404-
.to_result(DpdkError::from_errno)?;
403+
ffi::rte_eth_dev_get_port_by_name(device.clone().into_cstring().as_ptr(), &mut port_id)
404+
.into_result(DpdkError::from_errno)?;
405405
}
406406

407407
let port_id = PortId(port_id);
@@ -469,7 +469,7 @@ impl<'a> PortBuilder<'a> {
469469

470470
unsafe {
471471
ffi::rte_eth_dev_adjust_nb_rx_tx_desc(self.port_id.0, &mut rxd2, &mut txd2)
472-
.to_result(DpdkError::from_errno)?;
472+
.into_result(DpdkError::from_errno)?;
473473
}
474474

475475
info!(
@@ -523,7 +523,7 @@ impl<'a> PortBuilder<'a> {
523523
// must configure the device first before everything else.
524524
unsafe {
525525
ffi::rte_eth_dev_configure(self.port_id.0, len, len, &conf)
526-
.to_result(DpdkError::from_errno)?;
526+
.into_result(DpdkError::from_errno)?;
527527
}
528528

529529
// if the port is virtual, we will allocate it to the socket of
@@ -575,7 +575,7 @@ impl<'a> PortBuilder<'a> {
575575
ptr::null(),
576576
mempool,
577577
)
578-
.to_result(DpdkError::from_errno)?;
578+
.into_result(DpdkError::from_errno)?;
579579
}
580580

581581
// configures the TX queue with defaults
@@ -588,7 +588,7 @@ impl<'a> PortBuilder<'a> {
588588
socket_id.0 as raw::c_uint,
589589
ptr::null(),
590590
)
591-
.to_result(DpdkError::from_errno)?;
591+
.into_result(DpdkError::from_errno)?;
592592
}
593593

594594
#[cfg(feature = "pcap-dump")]

core/src/dpdk/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl PortStats {
6161
pub(crate) fn collect(&self) -> Result<Vec<(Key, Measurement)>> {
6262
let mut stats = ffi::rte_eth_stats::default();
6363
unsafe {
64-
ffi::rte_eth_stats_get(self.id.raw(), &mut stats).to_result(DpdkError::from_errno)?;
64+
ffi::rte_eth_stats_get(self.id.raw(), &mut stats).into_result(DpdkError::from_errno)?;
6565
}
6666

6767
let mut values = Vec::new();

core/src/ffi.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ impl AsStr for [raw::c_char] {
5656

5757
/// Simplify `String` and `&str` to `CString` conversion.
5858
pub(crate) trait ToCString {
59-
fn to_cstring(self) -> CString;
59+
fn into_cstring(self) -> CString;
6060
}
6161

6262
impl ToCString for String {
6363
#[inline]
64-
fn to_cstring(self) -> CString {
64+
fn into_cstring(self) -> CString {
6565
CString::new(self).unwrap()
6666
}
6767
}
6868

6969
impl ToCString for &str {
7070
#[inline]
71-
fn to_cstring(self) -> CString {
71+
fn into_cstring(self) -> CString {
7272
CString::new(self).unwrap()
7373
}
7474
}
@@ -79,14 +79,14 @@ impl ToCString for &str {
7979
///
8080
/// ```
8181
/// ffi::rte_eth_add_tx_callback(..., ..., ..., ...)
82-
/// .to_result(|_| {
82+
/// .into_result(|_| {
8383
/// DpdkError::new()
8484
/// })?;
8585
/// ```
8686
pub(crate) trait ToResult {
8787
type Ok;
8888

89-
fn to_result<E, F>(self, f: F) -> Result<Self::Ok>
89+
fn into_result<E, F>(self, f: F) -> Result<Self::Ok>
9090
where
9191
E: Error + Send + Sync + 'static,
9292
F: FnOnce(Self) -> E,
@@ -97,7 +97,7 @@ impl<T> ToResult for *mut T {
9797
type Ok = NonNull<T>;
9898

9999
#[inline]
100-
fn to_result<E, F>(self, f: F) -> Result<Self::Ok>
100+
fn into_result<E, F>(self, f: F) -> Result<Self::Ok>
101101
where
102102
E: Error + Send + Sync + 'static,
103103
F: FnOnce(Self) -> E,
@@ -110,7 +110,7 @@ impl<T> ToResult for *const T {
110110
type Ok = *const T;
111111

112112
#[inline]
113-
fn to_result<E, F>(self, f: F) -> Result<Self::Ok>
113+
fn into_result<E, F>(self, f: F) -> Result<Self::Ok>
114114
where
115115
E: Error + Send + Sync + 'static,
116116
F: FnOnce(Self) -> E,
@@ -127,7 +127,7 @@ impl ToResult for raw::c_int {
127127
type Ok = u32;
128128

129129
#[inline]
130-
fn to_result<E, F>(self, f: F) -> Result<Self::Ok>
130+
fn into_result<E, F>(self, f: F) -> Result<Self::Ok>
131131
where
132132
E: Error + Send + Sync + 'static,
133133
F: FnOnce(Self) -> E,

0 commit comments

Comments
 (0)