qemu-rust.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org
Subject: [PATCH 2/8] common: add prelude
Date: Mon, 17 Nov 2025 08:42:32 +0100	[thread overview]
Message-ID: <20251117074239.190424-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20251117074239.190424-1-pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/common/meson.build          | 13 +------------
 rust/common/src/lib.rs           |  5 +++++
 rust/common/src/prelude.rs       |  9 +++++++++
 rust/hw/char/pl011/src/device.rs |  2 +-
 rust/hw/timer/hpet/src/device.rs |  2 +-
 5 files changed, 17 insertions(+), 14 deletions(-)
 create mode 100644 rust/common/src/prelude.rs

diff --git a/rust/common/meson.build b/rust/common/meson.build
index aff601d1df2..db1365dbe0d 100644
--- a/rust/common/meson.build
+++ b/rust/common/meson.build
@@ -4,18 +4,7 @@ _common_cfg = run_command(rustc_args,
 
 _common_rs = static_library(
   'common',
-  structured_sources(
-    [
-      'src/lib.rs',
-      'src/assertions.rs',
-      'src/bitops.rs',
-      'src/callbacks.rs',
-      'src/errno.rs',
-      'src/opaque.rs',
-      'src/uninit.rs',
-      'src/zeroable.rs',
-    ],
-  ),
+  'src/lib.rs',
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
   rust_args: _common_cfg,
diff --git a/rust/common/src/lib.rs b/rust/common/src/lib.rs
index 8311bf945da..6093d01a388 100644
--- a/rust/common/src/lib.rs
+++ b/rust/common/src/lib.rs
@@ -15,6 +15,11 @@
 pub mod opaque;
 pub use opaque::{Opaque, Wrapper};
 
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
+
 pub mod uninit;
 pub use uninit::MaybeUninitField;
 
diff --git a/rust/common/src/prelude.rs b/rust/common/src/prelude.rs
new file mode 100644
index 00000000000..7d38ea12055
--- /dev/null
+++ b/rust/common/src/prelude.rs
@@ -0,0 +1,9 @@
+//! Essential types and traits intended for blanket imports.
+
+pub use crate::bitops::IntegerExt;
+pub use crate::uninit::MaybeUninitField;
+
+// Re-export commonly used macros
+pub use crate::static_assert;
+pub use crate::uninit_field_mut;
+pub use qemu_macros::TryInto;
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 18f40fdc58b..b7e8e393d2e 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -6,7 +6,7 @@
 
 use bql::BqlRefCell;
 use chardev::{CharFrontend, Chardev, Event};
-use common::{static_assert, uninit_field_mut};
+use common::prelude::*;
 use hwcore::{
     Clock, ClockEvent, DeviceImpl, DeviceMethods, DeviceState, IRQState, InterruptSource,
     ResetType, ResettablePhasesImpl, SysBusDevice, SysBusDeviceImpl, SysBusDeviceMethods,
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index 6e9c004ecae..e9c7afa24d5 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -11,7 +11,7 @@
 };
 
 use bql::{BqlCell, BqlRefCell};
-use common::{bitops::IntegerExt, uninit_field_mut};
+use common::prelude::*;
 use hwcore::{
     DeviceImpl, DeviceMethods, DeviceState, InterruptSource, ResetType, ResettablePhasesImpl,
     SysBusDevice, SysBusDeviceImpl, SysBusDeviceMethods,
-- 
2.51.1



  parent reply	other threads:[~2025-11-17  7:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
2025-11-17  7:42 ` [PATCH 1/8] util: add prelude Paolo Bonzini
2025-11-17  7:42 ` Paolo Bonzini [this message]
2025-11-17  7:42 ` [PATCH 3/8] hwcore: " Paolo Bonzini
2025-11-17  7:42 ` [PATCH 4/8] migration: " Paolo Bonzini
2025-11-17  7:42 ` [PATCH 5/8] chardev: " Paolo Bonzini
2025-11-17  7:42 ` [PATCH 6/8] bql: " Paolo Bonzini
2025-11-17  7:42 ` [PATCH 7/8] system: " Paolo Bonzini
2025-11-17  7:42 ` [PATCH 8/8] qom: add more to the prelude Paolo Bonzini
2025-11-17  8:03 ` [PATCH 0/8] rust: add preludes to all crates Marc-André Lureau
2025-11-17  8:36   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251117074239.190424-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).