Skip to content

Commit

Permalink
qcow2-rs: support 1.75.0 'async fn' in trait
Browse files Browse the repository at this point in the history
Conditionally support for 'async fn' in trait if toolchain is >= 1.75.0,
otherwise still #[async_trait] is used.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
  • Loading branch information
ming1 committed Jan 7, 2024
1 parent 62c0669 commit bfbd455
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ miniz_oxide = { version = "0.6.2", features = ["std"] }
futures = "0.3.29"
log = {version = "0.4", features = ["release_max_level_off"]}
env_logger = "0.9"
rustversion = "1.0.14"

[dev-dependencies]
tempfile = "3.6.0"
Expand Down
4 changes: 3 additions & 1 deletion src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::meta::{
};
use crate::zero_buf;
use async_recursion::async_recursion;
#[rustversion::before(1.75)]
use async_trait::async_trait;
use futures_locks::{RwLock as AsyncRwLock, RwLockWriteGuard as LockWriteGuard};
use miniz_oxide::inflate::core::{decompress as inflate, DecompressorOxide};
Expand All @@ -24,7 +25,8 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
///
/// these methods are called for reading data from image, writing data
/// to image, and discarding range.
#[async_trait(?Send)]
#[rustversion::attr(before(1.75), async_trait(?Send))]
#[rustversion::attr(since(1.75), allow(async_fn_in_trait))]
pub trait Qcow2IoOps {
async fn read_to(&self, offset: u64, buf: &mut [u8]) -> Qcow2Result<usize>;
async fn write_from(&self, offset: u64, buf: &[u8]) -> Qcow2Result<()>;
Expand Down
3 changes: 2 additions & 1 deletion src/sync_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::dev::Qcow2IoOps;
use crate::error::Qcow2Result;
#[rustversion::before(1.75)]
use async_trait::async_trait;
use nix::fcntl::{fallocate, FallocateFlags};
use std::cell::RefCell;
Expand Down Expand Up @@ -35,7 +36,7 @@ impl Qcow2IoSync {
}
}

#[async_trait(?Send)]
#[rustversion::attr(before(1.75), async_trait(?Send))]
impl Qcow2IoOps for Qcow2IoSync {
async fn read_to(&self, offset: u64, buf: &mut [u8]) -> Qcow2Result<usize> {
let res = unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/uring.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::dev::Qcow2IoOps;
use crate::error::Qcow2Result;
use crate::helpers::slice_to_vec;
#[rustversion::before(1.75)]
use async_trait::async_trait;
use nix::fcntl::{fallocate, FallocateFlags};
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -30,7 +31,7 @@ impl Qcow2IoUring {
}
}

#[async_trait(?Send)]
#[rustversion::attr(before(1.75), async_trait(?Send))]
impl Qcow2IoOps for Qcow2IoUring {
async fn read_to(&self, offset: u64, buf: &mut [u8]) -> Qcow2Result<usize> {
let ubuf = slice_to_vec::<u8>(buf);
Expand Down

0 comments on commit bfbd455

Please sign in to comment.