Bump Rust version requirement to 1.27.

This allows us to use:
(1.26)
  - impl Trait
  - autoderef in pattern matching
  - fixed slice patterns
  - inclusive ranges
(1.27)
  - dyn Trait
  - #[must_use] on functions

To prepare for edition change, dyn is added where applicable. Other
edition changes would require bumping the requirement even higher,
and so they are not applied for now.
This commit is contained in:
whitequark 2019-06-22 08:19:39 +00:00
parent 59f76f1868
commit 0134bb7399
13 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ include complicated compile-time computations, such as macro or type tricks, eve
at cost of performance degradation. at cost of performance degradation.
_smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs], _smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs],
and compiles on stable Rust 1.25 and later. and compiles on stable Rust 1.27 and later.
_smoltcp_ achieves [~Gbps of throughput](#examplesbenchmarkrs) when tested against _smoltcp_ achieves [~Gbps of throughput](#examplesbenchmarkrs) when tested against
the Linux TCP stack in loopback mode. the Linux TCP stack in loopback mode.

View File

@ -106,7 +106,7 @@ pub fn add_middleware_options(opts: &mut Options, _free: &mut Vec<&str>) {
} }
pub fn parse_middleware_options<D>(matches: &mut Matches, device: D, loopback: bool) pub fn parse_middleware_options<D>(matches: &mut Matches, device: D, loopback: bool)
-> FaultInjector<EthernetTracer<PcapWriter<D, Rc<PcapSink>>>> -> FaultInjector<EthernetTracer<PcapWriter<D, Rc<dyn PcapSink>>>>
where D: for<'a> Device<'a> where D: for<'a> Device<'a>
{ {
let drop_chance = matches.opt_str("drop-chance").map(|s| u8::from_str(&s).unwrap()) let drop_chance = matches.opt_str("drop-chance").map(|s| u8::from_str(&s).unwrap())
@ -122,7 +122,7 @@ pub fn parse_middleware_options<D>(matches: &mut Matches, device: D, loopback: b
let shaping_interval = matches.opt_str("shaping-interval").map(|s| u64::from_str(&s).unwrap()) let shaping_interval = matches.opt_str("shaping-interval").map(|s| u64::from_str(&s).unwrap())
.unwrap_or(0); .unwrap_or(0);
let pcap_writer: Box<io::Write>; let pcap_writer: Box<dyn io::Write>;
if let Some(pcap_filename) = matches.opt_str("pcap") { if let Some(pcap_filename) = matches.opt_str("pcap") {
pcap_writer = Box::new(File::create(pcap_filename).expect("cannot open file")) pcap_writer = Box::new(File::create(pcap_filename).expect("cannot open file"))
} else { } else {
@ -131,7 +131,7 @@ pub fn parse_middleware_options<D>(matches: &mut Matches, device: D, loopback: b
let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().subsec_nanos(); let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().subsec_nanos();
let device = PcapWriter::new(device, Rc::new(RefCell::new(pcap_writer)) as Rc<PcapSink>, let device = PcapWriter::new(device, Rc::new(RefCell::new(pcap_writer)) as Rc<dyn PcapSink>,
if loopback { PcapMode::TxOnly } else { PcapMode::Both }, if loopback { PcapMode::TxOnly } else { PcapMode::Both },
PcapLinkType::Ethernet); PcapLinkType::Ethernet);
let device = EthernetTracer::new(device, |_timestamp, _printer| { let device = EthernetTracer::new(device, |_timestamp, _printer| {

View File

@ -85,7 +85,7 @@ pub trait PcapSink {
} }
} }
impl<T: AsRef<PcapSink>> PcapSink for T { impl<T: AsRef<dyn PcapSink>> PcapSink for T {
fn write(&self, data: &[u8]) { fn write(&self, data: &[u8]) {
self.as_ref().write(data) self.as_ref().write(data)
} }

View File

@ -359,7 +359,7 @@ impl fmt::Display for Repr {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
match Packet::new_checked(buffer) { match Packet::new_checked(buffer) {
Err(err) => write!(f, "{}({})", indent, err), Err(err) => write!(f, "{}({})", indent, err),

View File

@ -212,7 +212,7 @@ impl<T: AsRef<[u8]>> fmt::Display for Frame<T> {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Frame<T> { impl<T: AsRef<[u8]>> PrettyPrint for Frame<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
let frame = match Frame::new_checked(buffer) { let frame = match Frame::new_checked(buffer) {
Err(err) => return write!(f, "{}({})", indent, err), Err(err) => return write!(f, "{}({})", indent, err),

View File

@ -534,7 +534,7 @@ impl<'a> fmt::Display for Repr<'a> {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
let packet = match Packet::new_checked(buffer) { let packet = match Packet::new_checked(buffer) {
Err(err) => return write!(f, "{}({})", indent, err), Err(err) => return write!(f, "{}({})", indent, err),

View File

@ -358,7 +358,7 @@ impl<'a> fmt::Display for Repr {
use super::pretty_print::{PrettyIndent, PrettyPrint}; use super::pretty_print::{PrettyIndent, PrettyPrint};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, fn pretty_print(buffer: &dyn AsRef<[u8]>,
f: &mut fmt::Formatter, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) indent: &mut PrettyIndent)
-> fmt::Result { -> fmt::Result {

View File

@ -665,7 +665,7 @@ impl fmt::Display for Repr {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
use wire::ip::checksum::format_checksum; use wire::ip::checksum::format_checksum;

View File

@ -652,7 +652,7 @@ use super::pretty_print::{PrettyPrint, PrettyIndent};
// TODO: This is very similar to the implementation for IPv4. Make // TODO: This is very similar to the implementation for IPv4. Make
// a way to have less copy and pasted code here. // a way to have less copy and pasted code here.
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
let (ip_repr, payload) = match Packet::new_checked(buffer) { let (ip_repr, payload) = match Packet::new_checked(buffer) {
Err(err) => return write!(f, "{}({})", indent, err), Err(err) => return write!(f, "{}({})", indent, err),

View File

@ -590,7 +590,7 @@ impl<'a> fmt::Display for Repr<'a> {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for NdiscOption<T> { impl<T: AsRef<[u8]>> PrettyPrint for NdiscOption<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
match NdiscOption::new_checked(buffer) { match NdiscOption::new_checked(buffer) {
Err(err) => return write!(f, "{}({})", indent, err), Err(err) => return write!(f, "{}({})", indent, err),

View File

@ -71,20 +71,20 @@ pub trait PrettyPrint {
/// ///
/// `pretty_print` accepts a buffer and not a packet wrapper because the packet might /// `pretty_print` accepts a buffer and not a packet wrapper because the packet might
/// be truncated, and so it might not be possible to create the packet wrapper. /// be truncated, and so it might not be possible to create the packet wrapper.
fn pretty_print(buffer: &AsRef<[u8]>, fmt: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, fmt: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result; indent: &mut PrettyIndent) -> fmt::Result;
} }
/// Wrapper for using a `PrettyPrint` where a `Display` is expected. /// Wrapper for using a `PrettyPrint` where a `Display` is expected.
pub struct PrettyPrinter<'a, T: PrettyPrint> { pub struct PrettyPrinter<'a, T: PrettyPrint> {
prefix: &'static str, prefix: &'static str,
buffer: &'a AsRef<[u8]>, buffer: &'a dyn AsRef<[u8]>,
phantom: PhantomData<T> phantom: PhantomData<T>
} }
impl<'a, T: PrettyPrint> PrettyPrinter<'a, T> { impl<'a, T: PrettyPrint> PrettyPrinter<'a, T> {
/// Format the listing with the recorded parameters when Display::fmt is called. /// Format the listing with the recorded parameters when Display::fmt is called.
pub fn new(prefix: &'static str, buffer: &'a AsRef<[u8]>) -> PrettyPrinter<'a, T> { pub fn new(prefix: &'static str, buffer: &'a dyn AsRef<[u8]>) -> PrettyPrinter<'a, T> {
PrettyPrinter { PrettyPrinter {
prefix: prefix, prefix: prefix,
buffer: buffer, buffer: buffer,

View File

@ -1012,7 +1012,7 @@ impl<'a> fmt::Display for Repr<'a> {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
match Packet::new_checked(buffer) { match Packet::new_checked(buffer) {
Err(err) => write!(f, "{}({})", indent, err), Err(err) => write!(f, "{}({})", indent, err),

View File

@ -275,7 +275,7 @@ impl<'a> fmt::Display for Repr<'a> {
use super::pretty_print::{PrettyPrint, PrettyIndent}; use super::pretty_print::{PrettyPrint, PrettyIndent};
impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> { impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter,
indent: &mut PrettyIndent) -> fmt::Result { indent: &mut PrettyIndent) -> fmt::Result {
match Packet::new_checked(buffer) { match Packet::new_checked(buffer) {
Err(err) => write!(f, "{}({})", indent, err), Err(err) => write!(f, "{}({})", indent, err),