Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ jobs:
disable_extra_builds: true
disable_tests: true
target: aarch64-apple-darwin
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-arm-linux-androideabi:
uses: ./.github/workflows/build.yaml
with:
disable_extra_builds: true
disable_tests: true
target: arm-linux-androideabi
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-x86_64-unknown-freebsd:
uses: ./.github/workflows/build.yaml
with:
disable_extra_builds: true
disable_tests: true
target: x86_64-unknown-freebsd
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-x86_64-unknown-linux-gnu:
uses: ./.github/workflows/build.yaml
Expand All @@ -77,7 +77,7 @@ jobs:
disable_tests: true
extra_packages: libudev-dev
target: x86_64-unknown-linux-gnu
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-x86_64-unknown-linux-musl:
uses: ./.github/workflows/build.yaml
Expand All @@ -86,7 +86,7 @@ jobs:
disable_tests: true
extra_packages: gcc-aarch64-linux-gnu
target: aarch64-unknown-linux-musl
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-x86_64-pc-windows-msvc:
uses: ./.github/workflows/build.yaml
Expand All @@ -95,15 +95,15 @@ jobs:
disable_tests: true
runs_on: windows-2019
target: x86_64-pc-windows-msvc
toolchain: "1.59.0"
toolchain: "1.69.0"

msrv-x86_64-unknown-netbsd:
uses: ./.github/workflows/build.yaml
with:
disable_extra_builds: true
disable_tests: true
target: x86_64-unknown-netbsd
toolchain: "1.59.0"
toolchain: "1.69.0"

# --------------------------------------------------------------------------
# Semantic Versioning
Expand Down
15 changes: 2 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
"Jesse Braham <[email protected]>",
]
edition = "2021"
rust-version = "1.59.0"
rust-version = "1.69.0"
description = "A cross-platform low-level serial port library."
documentation = "https://docs.rs/serialport"
repository = "https://github.com/serialport/serialport-rs"
Expand All @@ -16,7 +16,7 @@ categories = ["hardware-support"]

[target."cfg(unix)".dependencies]
bitflags = "2.4.0"
nix = { version = "0.26", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }
nix = { version = "0.30", default-features = false, features = ["fs", "ioctl", "poll", "signal", "term"] }

[target.'cfg(all(target_os = "linux", not(target_env = "musl")))'.dependencies]
libudev = { version = "0.3.0", optional = true }
Expand Down Expand Up @@ -44,21 +44,10 @@ serde = { version = "1.0", features = ["derive"], optional = true }
assert_hex = "0.4.1"
clap = { version = "3.1.6", features = ["derive"] }
envconfig = "0.10.0"
# TODES Remove pinning this subdependency (of clap) when we are bumping our
# MSRV (libc raised its MSRV with a patch release 0.2.167 from 1.19.0 to
# 1.63.0). Trick the resolver into picking a compatible release of libc by
# adding it as a direct dependency meanwhile.
libc = ">=0.2.0, <=0.2.163"
# TODO: Remove pinning this subdependency of clap when we are bumping our MSRV.
# (There has been an incompatible change with the MSRV of os_str_bytes with
# 6.6.0) Until then we are tricking the dependency resolver into using a
# compatible version by adding it as a direct dependency here.
os_str_bytes = ">=6.0, <6.6.0"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"
rstest = { version = "0.12.0", default-features = false }
rstest_reuse = "0.6.0"
rustversion = "1.0.16"

[features]
default = ["libudev"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![crates.io version badge](https://img.shields.io/crates/v/serialport.svg)](https://crates.io/crates/serialport)
[![Documentation](https://docs.rs/serialport/badge.svg)](https://docs.rs/serialport)
[![GitHub workflow status](https://img.shields.io/github/actions/workflow/status/serialport/serialport-rs/ci.yaml?branch=main&logo=github)](https://github.com/serialport/serialport-rs/actions)
[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust-1.59.0-blue?logo=rust)](https://blog.rust-lang.org/2022/02/24/Rust-1.59.0.html)
[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust-1.69.0-blue?logo=rust)](https://blog.rust-lang.org/2023/04/20/Rust-1.69.0/)

# Introduction

Expand Down Expand Up @@ -105,7 +105,7 @@ can help debug software or hardware errors.

# Dependencies

Rust versions 1.59.0 and higher are supported by the library itself. There are
Rust versions 1.69.0 and higher are supported by the library itself. There are
examples requiring newer versions of Rust.

For GNU/Linux `pkg-config` headers are required:
Expand Down
10 changes: 0 additions & 10 deletions examples/loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,6 @@ fn loopback_standard<'a>(
}
}

#[rustversion::before(1.63)]
fn loopback_split<'a>(
_port: &mut Box<dyn SerialPort>,
_read_stats: &mut Stats<'a>,
_write_stats: &mut Stats<'a>,
) {
unimplemented!("requires Rust 1.63 or later");
}

#[rustversion::since(1.63)]
fn loopback_split<'a>(
port: &mut Box<dyn SerialPort>,
read_stats: &mut Stats<'a>,
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,9 @@ pub struct SerialPortBuilder {

impl SerialPortBuilder {
/// Set the path to the serial port
// TODO: Switch to `clone_into` when bumping our MSRV past 1.63 and remove this exemption.
#[allow(clippy::assigning_clones)]
#[must_use]
pub fn path<'a>(mut self, path: impl Into<std::borrow::Cow<'a, str>>) -> Self {
self.path = path.into().as_ref().to_owned();
self.path = path.into().into_owned();
self
}

Expand Down
41 changes: 18 additions & 23 deletions src/posix/poll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(non_camel_case_types, dead_code)]

use std::io;
use std::os::unix::io::RawFd;
use std::os::fd::AsFd;
use std::slice;
use std::time::Duration;

Expand All @@ -12,18 +12,18 @@ use nix::sys::signal::SigSet;
#[cfg(any(target_os = "linux", test))]
use nix::sys::time::TimeSpec;

pub fn wait_read_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
wait_fd(fd, PollFlags::POLLIN, timeout)
pub fn wait_read_fd<Fd: AsFd>(fd: Fd, timeout: Duration) -> io::Result<()> {
wait_fd(fd.as_fd(), PollFlags::POLLIN, timeout)
}

pub fn wait_write_fd(fd: RawFd, timeout: Duration) -> io::Result<()> {
wait_fd(fd, PollFlags::POLLOUT, timeout)
pub fn wait_write_fd<Fd: AsFd>(fd: Fd, timeout: Duration) -> io::Result<()> {
wait_fd(fd.as_fd(), PollFlags::POLLOUT, timeout)
}

fn wait_fd(fd: RawFd, events: PollFlags, timeout: Duration) -> io::Result<()> {
fn wait_fd<Fd: AsFd>(fd: Fd, events: PollFlags, timeout: Duration) -> io::Result<()> {
use nix::errno::Errno::{EIO, EPIPE};

let mut fd = PollFd::new(fd, events);
let mut fd = PollFd::new(fd.as_fd(), events);

let wait = match poll_clamped(&mut fd, timeout) {
Ok(r) => r,
Expand Down Expand Up @@ -86,44 +86,39 @@ fn clamped_time_spec(duration: Duration) -> TimeSpec {
// by `poll`.
#[cfg(not(target_os = "linux"))]
fn poll_clamped(fd: &mut PollFd, timeout: Duration) -> nix::Result<c_int> {
let millis = clamped_millis_c_int(timeout);
let millis = clamped_duration_nix(timeout);
nix::poll::poll(slice::from_mut(fd), millis)
}

#[cfg(any(not(target_os = "linux"), test))]
fn clamped_millis_c_int(duration: Duration) -> c_int {
let secs_limit = (c_int::MAX as u64) / 1000;
let secs = duration.as_secs();

if secs <= secs_limit {
secs as c_int * 1000 + duration.subsec_millis() as c_int
} else {
c_int::MAX
}
fn clamped_duration_nix(duration: Duration) -> nix::poll::PollTimeout {
nix::poll::PollTimeout::try_from(duration).unwrap_or(nix::poll::PollTimeout::MAX)
}

#[cfg(test)]
mod tests {
use nix::poll::PollTimeout;

use super::*;
use crate::tests::timeout::MONOTONIC_DURATIONS;

#[test]
fn clamped_millis_c_int_is_monotonic() {
let mut last = clamped_millis_c_int(Duration::ZERO);
fn clamped_duration_nix_is_monotonic() {
let mut last = clamped_duration_nix(Duration::ZERO);

for (i, d) in MONOTONIC_DURATIONS.iter().enumerate() {
let next = clamped_millis_c_int(*d);
let next = clamped_duration_nix(*d);
assert!(
next >= last,
"{next} >= {last} failed for {d:?} at index {i}"
"{next:?} >= {last:?} failed for {d:?} at index {i}"
);
last = next;
}
}

#[test]
fn clamped_millis_c_int_zero_is_zero() {
assert_eq!(0, clamped_millis_c_int(Duration::ZERO));
fn clamped_duration_nix_zero_is_zero() {
assert_eq!(PollTimeout::ZERO, clamped_duration_nix(Duration::ZERO));
}

#[test]
Expand Down
Loading
Loading