qemu-rust.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] rust: add preludes to all crates
@ 2025-11-17  7:42 Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 1/8] util: add prelude Paolo Bonzini
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

This series adds a prelude module to all crates, so that
it becomes possible to import from each crate with either
of the following

   use XYZ::prelude::*;
   use XYZ::{self, prelude::*};

The latter is used for items that have a "too common"
name to be put in the prelude: util::Error, util::Result,
migration::Infallible.

Thanks,

Paolo

Paolo Bonzini (8):
  util: add prelude
  common: add prelude
  hwcore: add prelude
  migration: add prelude
  chardev: add prelude
  bql: add prelude
  system: add prelude
  qom: add more to the prelude

 rust/bql/meson.build              |  1 +
 rust/bql/src/lib.rs               |  5 +++++
 rust/bql/src/prelude.rs           |  4 ++++
 rust/chardev/meson.build          |  1 +
 rust/chardev/src/chardev.rs       |  2 +-
 rust/chardev/src/lib.rs           |  5 +++++
 rust/chardev/src/prelude.rs       |  5 +++++
 rust/common/meson.build           | 13 +------------
 rust/common/src/lib.rs            |  5 +++++
 rust/common/src/prelude.rs        |  9 +++++++++
 rust/hw/char/pl011/src/device.rs  | 22 ++++++++--------------
 rust/hw/core/meson.build          |  1 +
 rust/hw/core/src/lib.rs           |  5 +++++
 rust/hw/core/src/prelude.rs       | 14 ++++++++++++++
 rust/hw/core/src/qdev.rs          |  2 +-
 rust/hw/core/src/sysbus.rs        |  2 +-
 rust/hw/core/tests/tests.rs       |  8 ++++----
 rust/hw/timer/hpet/src/device.rs  | 26 +++++++++-----------------
 rust/hw/timer/hpet/src/fw_cfg.rs  |  2 +-
 rust/migration/meson.build        |  1 +
 rust/migration/src/lib.rs         |  5 +++++
 rust/migration/src/migratable.rs  |  2 +-
 rust/migration/src/prelude.rs     | 19 +++++++++++++++++++
 rust/qom/src/prelude.rs           |  4 ++++
 rust/system/meson.build           |  1 +
 rust/system/src/lib.rs            |  5 +++++
 rust/system/src/prelude.rs        |  8 ++++++++
 rust/tests/tests/vmstate_tests.rs |  7 +++----
 rust/util/meson.build             |  1 +
 rust/util/src/lib.rs              |  5 +++++
 rust/util/src/prelude.rs          | 11 +++++++++++
 31 files changed, 145 insertions(+), 56 deletions(-)
 create mode 100644 rust/bql/src/prelude.rs
 create mode 100644 rust/chardev/src/prelude.rs
 create mode 100644 rust/common/src/prelude.rs
 create mode 100644 rust/hw/core/src/prelude.rs
 create mode 100644 rust/migration/src/prelude.rs
 create mode 100644 rust/system/src/prelude.rs
 create mode 100644 rust/util/src/prelude.rs

-- 
2.51.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/8] util: add prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 2/8] common: " Paolo Bonzini
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs |  2 +-
 rust/hw/timer/hpet/src/device.rs |  5 +----
 rust/hw/timer/hpet/src/fw_cfg.rs |  2 +-
 rust/util/meson.build            |  1 +
 rust/util/src/lib.rs             |  5 +++++
 rust/util/src/prelude.rs         | 11 +++++++++++
 6 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 rust/util/src/prelude.rs

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 04155dabe1a..18f40fdc58b 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -17,7 +17,7 @@
 };
 use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
 use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder};
-use util::{log::Log, log_mask_ln, ResultExt};
+use util::prelude::*;
 
 use crate::registers::{self, Interrupt, RegisterOffset};
 
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index 3564aa79c6e..6e9c004ecae 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -25,10 +25,7 @@
     bindings::{address_space_memory, address_space_stl_le, hwaddr},
     MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
 };
-use util::{
-    ensure,
-    timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND},
-};
+use util::prelude::*;
 
 use crate::fw_cfg::HPETFwConfig;
 
diff --git a/rust/hw/timer/hpet/src/fw_cfg.rs b/rust/hw/timer/hpet/src/fw_cfg.rs
index 777fc8ef45e..ad80acd998c 100644
--- a/rust/hw/timer/hpet/src/fw_cfg.rs
+++ b/rust/hw/timer/hpet/src/fw_cfg.rs
@@ -5,7 +5,7 @@
 use std::ptr::addr_of_mut;
 
 use common::Zeroable;
-use util::{self, ensure};
+use util::{self, prelude::*};
 
 /// Each `HPETState` represents a Event Timer Block. The v1 spec supports
 /// up to 8 blocks. QEMU only uses 1 block (in PC machine).
diff --git a/rust/util/meson.build b/rust/util/meson.build
index 8ad344dccbd..da5d0f779d1 100644
--- a/rust/util/meson.build
+++ b/rust/util/meson.build
@@ -34,6 +34,7 @@ _util_rs = static_library(
       'src/error.rs',
       'src/log.rs',
       'src/module.rs',
+      'src/prelude.rs',
       'src/timer.rs',
     ],
     {'.': _util_bindings_inc_rs}
diff --git a/rust/util/src/lib.rs b/rust/util/src/lib.rs
index d14aa14ca77..7d2de3ed811 100644
--- a/rust/util/src/lib.rs
+++ b/rust/util/src/lib.rs
@@ -4,6 +4,11 @@
 pub mod error;
 pub mod log;
 pub mod module;
+
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
 pub mod timer;
 
 pub use error::{Error, Result, ResultExt};
diff --git a/rust/util/src/prelude.rs b/rust/util/src/prelude.rs
new file mode 100644
index 00000000000..f52e7100e9f
--- /dev/null
+++ b/rust/util/src/prelude.rs
@@ -0,0 +1,11 @@
+//! Essential types and traits intended for blanket imports.
+
+pub use crate::error::ResultExt;
+pub use crate::log::Log;
+pub use crate::timer::Timer;
+pub use crate::timer::CLOCK_VIRTUAL;
+pub use crate::timer::NANOSECONDS_PER_SECOND;
+
+// Re-export commonly used macros
+pub use crate::ensure;
+pub use crate::log_mask_ln;
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/8] common: add prelude
  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
  2025-11-17  7:42 ` [PATCH 3/8] hwcore: " Paolo Bonzini
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/8] hwcore: add prelude
  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 ` [PATCH 2/8] common: " Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 4/8] migration: " Paolo Bonzini
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

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

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index b7e8e393d2e..164f27d5bb2 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -7,10 +7,7 @@
 use bql::BqlRefCell;
 use chardev::{CharFrontend, Chardev, Event};
 use common::prelude::*;
-use hwcore::{
-    Clock, ClockEvent, DeviceImpl, DeviceMethods, DeviceState, IRQState, InterruptSource,
-    ResetType, ResettablePhasesImpl, SysBusDevice, SysBusDeviceImpl, SysBusDeviceMethods,
-};
+use hwcore::{prelude::*, ClockEvent, IRQState};
 use migration::{
     self, impl_vmstate_forward, impl_vmstate_struct, vmstate_fields, vmstate_of,
     vmstate_subsections, vmstate_unused, VMStateDescription, VMStateDescriptionBuilder,
diff --git a/rust/hw/core/meson.build b/rust/hw/core/meson.build
index 1560dd20c6b..fa1765a2302 100644
--- a/rust/hw/core/meson.build
+++ b/rust/hw/core/meson.build
@@ -51,6 +51,7 @@ _hwcore_rs = static_library(
       'src/lib.rs',
       'src/bindings.rs',
       'src/irq.rs',
+      'src/prelude.rs',
       'src/qdev.rs',
       'src/sysbus.rs',
     ],
diff --git a/rust/hw/core/src/lib.rs b/rust/hw/core/src/lib.rs
index b40801eb843..491743d2b9d 100644
--- a/rust/hw/core/src/lib.rs
+++ b/rust/hw/core/src/lib.rs
@@ -8,6 +8,11 @@
 mod irq;
 pub use irq::*;
 
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
+
 mod qdev;
 pub use qdev::*;
 
diff --git a/rust/hw/core/src/prelude.rs b/rust/hw/core/src/prelude.rs
new file mode 100644
index 00000000000..c544c317b39
--- /dev/null
+++ b/rust/hw/core/src/prelude.rs
@@ -0,0 +1,14 @@
+//! Essential types and traits intended for blanket imports.
+
+pub use crate::qdev::Clock;
+pub use crate::qdev::DeviceState;
+pub use crate::qdev::DeviceImpl;
+pub use crate::qdev::DeviceMethods;
+pub use crate::qdev::ResettablePhasesImpl;
+pub use crate::qdev::ResetType;
+
+pub use crate::sysbus::SysBusDevice;
+pub use crate::sysbus::SysBusDeviceImpl;
+pub use crate::sysbus::SysBusDeviceMethods;
+
+pub use crate::irq::InterruptSource;
diff --git a/rust/hw/core/tests/tests.rs b/rust/hw/core/tests/tests.rs
index 247d812866d..b39d1501d5b 100644
--- a/rust/hw/core/tests/tests.rs
+++ b/rust/hw/core/tests/tests.rs
@@ -5,7 +5,7 @@
 use std::{ffi::CStr, ptr::addr_of};
 
 use bql::BqlCell;
-use hwcore::{DeviceImpl, DeviceState, ResettablePhasesImpl, SysBusDevice};
+use hwcore::prelude::*;
 use migration::{VMStateDescription, VMStateDescriptionBuilder};
 use qom::{prelude::*, ObjectImpl, ParentField};
 use util::bindings::{module_call_init, module_init_type};
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index e9c7afa24d5..7ab9897cdfb 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -12,10 +12,7 @@
 
 use bql::{BqlCell, BqlRefCell};
 use common::prelude::*;
-use hwcore::{
-    DeviceImpl, DeviceMethods, DeviceState, InterruptSource, ResetType, ResettablePhasesImpl,
-    SysBusDevice, SysBusDeviceImpl, SysBusDeviceMethods,
-};
+use hwcore::prelude::*;
 use migration::{
     self, impl_vmstate_struct, vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,
     VMStateDescription, VMStateDescriptionBuilder,
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/8] migration: add prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (2 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 3/8] hwcore: " Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 5/8] chardev: " Paolo Bonzini
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/chardev/src/prelude.rs       |  3 +++
 rust/hw/char/pl011/src/device.rs  |  5 +----
 rust/hw/core/tests/tests.rs       |  2 +-
 rust/hw/timer/hpet/src/device.rs  |  5 +----
 rust/migration/meson.build        |  1 +
 rust/migration/src/lib.rs         |  5 +++++
 rust/migration/src/prelude.rs     | 19 +++++++++++++++++++
 rust/tests/tests/vmstate_tests.rs |  5 ++---
 8 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 rust/chardev/src/prelude.rs
 create mode 100644 rust/migration/src/prelude.rs

diff --git a/rust/chardev/src/prelude.rs b/rust/chardev/src/prelude.rs
new file mode 100644
index 00000000000..9f0b561bfab
--- /dev/null
+++ b/rust/chardev/src/prelude.rs
@@ -0,0 +1,3 @@
+//! Essential types and traits intended for blanket imports.
+
+pub use crate::chardev::{Chardev, CharFrontend, Event};
\ No newline at end of file
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 164f27d5bb2..2e4ccc9b231 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -8,10 +8,7 @@
 use chardev::{CharFrontend, Chardev, Event};
 use common::prelude::*;
 use hwcore::{prelude::*, ClockEvent, IRQState};
-use migration::{
-    self, impl_vmstate_forward, impl_vmstate_struct, vmstate_fields, vmstate_of,
-    vmstate_subsections, vmstate_unused, VMStateDescription, VMStateDescriptionBuilder,
-};
+use migration::{self, prelude::*};
 use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
 use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder};
 use util::prelude::*;
diff --git a/rust/hw/core/tests/tests.rs b/rust/hw/core/tests/tests.rs
index b39d1501d5b..f38376d0016 100644
--- a/rust/hw/core/tests/tests.rs
+++ b/rust/hw/core/tests/tests.rs
@@ -6,7 +6,7 @@
 
 use bql::BqlCell;
 use hwcore::prelude::*;
-use migration::{VMStateDescription, VMStateDescriptionBuilder};
+use migration::prelude::*;
 use qom::{prelude::*, ObjectImpl, ParentField};
 use util::bindings::{module_call_init, module_init_type};
 
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index 7ab9897cdfb..4ff1779a3d2 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -13,10 +13,7 @@
 use bql::{BqlCell, BqlRefCell};
 use common::prelude::*;
 use hwcore::prelude::*;
-use migration::{
-    self, impl_vmstate_struct, vmstate_fields, vmstate_of, vmstate_subsections, vmstate_validate,
-    VMStateDescription, VMStateDescriptionBuilder,
-};
+use migration::{self, prelude::*};
 use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
 use system::{
     bindings::{address_space_memory, address_space_stl_le, hwaddr},
diff --git a/rust/migration/meson.build b/rust/migration/meson.build
index 444494700ad..d7af2129490 100644
--- a/rust/migration/meson.build
+++ b/rust/migration/meson.build
@@ -32,6 +32,7 @@ _migration_rs = static_library(
       'src/lib.rs',
       'src/bindings.rs',
       'src/migratable.rs',
+      'src/prelude.rs',
       'src/vmstate.rs',
     ],
     {'.' : _migration_bindings_inc_rs},
diff --git a/rust/migration/src/lib.rs b/rust/migration/src/lib.rs
index c9bdf0d4133..32e182e716a 100644
--- a/rust/migration/src/lib.rs
+++ b/rust/migration/src/lib.rs
@@ -7,5 +7,10 @@
 pub mod migratable;
 pub use migratable::*;
 
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
+
 pub mod vmstate;
 pub use vmstate::*;
diff --git a/rust/migration/src/prelude.rs b/rust/migration/src/prelude.rs
new file mode 100644
index 00000000000..797e7ec59d1
--- /dev/null
+++ b/rust/migration/src/prelude.rs
@@ -0,0 +1,19 @@
+//! Essential types and traits intended for blanket imports.
+
+// Core migration traits and types
+pub use crate::vmstate::VMState;
+pub use crate::vmstate::VMStateDescription;
+pub use crate::vmstate::VMStateDescriptionBuilder;
+
+// Migratable wrappers
+pub use crate::migratable::Migratable;
+pub use crate::ToMigrationState;
+
+// Commonly used macros
+pub use crate::impl_vmstate_forward;
+pub use crate::impl_vmstate_struct;
+pub use crate::vmstate_fields;
+pub use crate::vmstate_of;
+pub use crate::vmstate_subsections;
+pub use crate::vmstate_unused;
+pub use crate::vmstate_validate;
diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_tests.rs
index fa9bbd6a122..c3f9e1c7436 100644
--- a/rust/tests/tests/vmstate_tests.rs
+++ b/rust/tests/tests/vmstate_tests.rs
@@ -16,9 +16,8 @@
         vmstate_info_bool, vmstate_info_int32, vmstate_info_int64, vmstate_info_int8,
         vmstate_info_uint64, vmstate_info_uint8, vmstate_info_unused_buffer, VMStateFlags,
     },
-    impl_vmstate_forward, impl_vmstate_struct,
-    vmstate::{VMStateDescription, VMStateDescriptionBuilder, VMStateField},
-    vmstate_fields, vmstate_of, vmstate_unused, vmstate_validate,
+    prelude::*,
+    vmstate::VMStateField,
 };
 
 const FOO_ARRAY_MAX: usize = 3;
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/8] chardev: add prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (3 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 4/8] migration: " Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 6/8] bql: " Paolo Bonzini
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/chardev/meson.build         | 1 +
 rust/chardev/src/lib.rs          | 5 +++++
 rust/chardev/src/prelude.rs      | 4 +++-
 rust/hw/char/pl011/src/device.rs | 2 +-
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/rust/chardev/meson.build b/rust/chardev/meson.build
index 36ada7c4546..d89baba8e20 100644
--- a/rust/chardev/meson.build
+++ b/rust/chardev/meson.build
@@ -30,6 +30,7 @@ _chardev_rs = static_library(
       'src/lib.rs',
       'src/bindings.rs',
       'src/chardev.rs',
+      'src/prelude.rs',
     ],
     {'.': _chardev_bindings_inc_rs}
   ),
diff --git a/rust/chardev/src/lib.rs b/rust/chardev/src/lib.rs
index 2e549f99d91..93a28725932 100644
--- a/rust/chardev/src/lib.rs
+++ b/rust/chardev/src/lib.rs
@@ -4,3 +4,8 @@
 
 mod chardev;
 pub use chardev::*;
+
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
diff --git a/rust/chardev/src/prelude.rs b/rust/chardev/src/prelude.rs
index 9f0b561bfab..f949d925399 100644
--- a/rust/chardev/src/prelude.rs
+++ b/rust/chardev/src/prelude.rs
@@ -1,3 +1,5 @@
 //! Essential types and traits intended for blanket imports.
 
-pub use crate::chardev::{Chardev, CharFrontend, Event};
\ No newline at end of file
+pub use crate::chardev::Chardev;
+pub use crate::chardev::CharFrontend;
+pub use crate::chardev::Event;
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 2e4ccc9b231..ff929e60993 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -5,7 +5,7 @@
 use std::{ffi::CStr, mem::size_of};
 
 use bql::BqlRefCell;
-use chardev::{CharFrontend, Chardev, Event};
+use chardev::prelude::*;
 use common::prelude::*;
 use hwcore::{prelude::*, ClockEvent, IRQState};
 use migration::{self, prelude::*};
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/8] bql: add prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (4 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 5/8] chardev: " Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  7:42 ` [PATCH 7/8] system: " Paolo Bonzini
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/bql/meson.build              | 1 +
 rust/bql/src/lib.rs               | 5 +++++
 rust/bql/src/prelude.rs           | 4 ++++
 rust/chardev/src/chardev.rs       | 2 +-
 rust/hw/char/pl011/src/device.rs  | 2 +-
 rust/hw/core/tests/tests.rs       | 2 +-
 rust/hw/timer/hpet/src/device.rs  | 2 +-
 rust/migration/src/migratable.rs  | 2 +-
 rust/tests/tests/vmstate_tests.rs | 2 +-
 9 files changed, 16 insertions(+), 6 deletions(-)
 create mode 100644 rust/bql/src/prelude.rs

diff --git a/rust/bql/meson.build b/rust/bql/meson.build
index 091372dd7b6..90aaadaa6d6 100644
--- a/rust/bql/meson.build
+++ b/rust/bql/meson.build
@@ -31,6 +31,7 @@ _bql_rs = static_library(
       'src/lib.rs',
       'src/bindings.rs',
       'src/cell.rs',
+      'src/prelude.rs',
     ],
     {'.': _bql_bindings_inc_rs}
   ),
diff --git a/rust/bql/src/lib.rs b/rust/bql/src/lib.rs
index ef08221e9c1..d2fea5db1ac 100644
--- a/rust/bql/src/lib.rs
+++ b/rust/bql/src/lib.rs
@@ -6,6 +6,11 @@
 mod cell;
 pub use cell::*;
 
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
+
 /// An internal function that is used by doctests.
 pub fn start_test() {
     // SAFETY: integration tests are run with --test-threads=1, while
diff --git a/rust/bql/src/prelude.rs b/rust/bql/src/prelude.rs
new file mode 100644
index 00000000000..42031ec18ab
--- /dev/null
+++ b/rust/bql/src/prelude.rs
@@ -0,0 +1,4 @@
+//! Essential types and traits intended for blanket imports.
+
+pub use crate::cell::BqlCell;
+pub use crate::cell::BqlRefCell;
diff --git a/rust/chardev/src/chardev.rs b/rust/chardev/src/chardev.rs
index f0b7975dbf7..fb9674b3fb4 100644
--- a/rust/chardev/src/chardev.rs
+++ b/rust/chardev/src/chardev.rs
@@ -18,7 +18,7 @@
     slice,
 };
 
-use bql::{BqlRefCell, BqlRefMut};
+use bql::{prelude::*, BqlRefMut};
 use common::{callbacks::FnCall, errno, Opaque};
 use qom::prelude::*;
 
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index ff929e60993..be1bdf5ab12 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -4,7 +4,7 @@
 
 use std::{ffi::CStr, mem::size_of};
 
-use bql::BqlRefCell;
+use bql::prelude::*;
 use chardev::prelude::*;
 use common::prelude::*;
 use hwcore::{prelude::*, ClockEvent, IRQState};
diff --git a/rust/hw/core/tests/tests.rs b/rust/hw/core/tests/tests.rs
index f38376d0016..e60c9d018f5 100644
--- a/rust/hw/core/tests/tests.rs
+++ b/rust/hw/core/tests/tests.rs
@@ -4,7 +4,7 @@
 
 use std::{ffi::CStr, ptr::addr_of};
 
-use bql::BqlCell;
+use bql::prelude::*;
 use hwcore::prelude::*;
 use migration::prelude::*;
 use qom::{prelude::*, ObjectImpl, ParentField};
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index 4ff1779a3d2..b7153a46e31 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -10,7 +10,7 @@
     slice::from_ref,
 };
 
-use bql::{BqlCell, BqlRefCell};
+use bql::prelude::*;
 use common::prelude::*;
 use hwcore::prelude::*;
 use migration::{self, prelude::*};
diff --git a/rust/migration/src/migratable.rs b/rust/migration/src/migratable.rs
index ded6fe8f4a6..ce603867502 100644
--- a/rust/migration/src/migratable.rs
+++ b/rust/migration/src/migratable.rs
@@ -9,7 +9,7 @@
     sync::{Arc, Mutex},
 };
 
-use bql::{BqlCell, BqlRefCell};
+use bql::prelude::*;
 use common::Zeroable;
 
 use crate::{
diff --git a/rust/tests/tests/vmstate_tests.rs b/rust/tests/tests/vmstate_tests.rs
index c3f9e1c7436..87176a80990 100644
--- a/rust/tests/tests/vmstate_tests.rs
+++ b/rust/tests/tests/vmstate_tests.rs
@@ -9,7 +9,7 @@
     slice,
 };
 
-use bql::BqlCell;
+use bql::prelude::*;
 use common::Opaque;
 use migration::{
     bindings::{
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/8] system: add prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (5 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 6/8] bql: " Paolo Bonzini
@ 2025-11-17  7:42 ` 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
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

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

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index be1bdf5ab12..0b1bb2d5a3b 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -10,7 +10,7 @@
 use hwcore::{prelude::*, ClockEvent, IRQState};
 use migration::{self, prelude::*};
 use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
-use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder};
+use system::prelude::*;
 use util::prelude::*;
 
 use crate::registers::{self, Interrupt, RegisterOffset};
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index b7153a46e31..c5cdb87b073 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -16,8 +16,9 @@
 use migration::{self, prelude::*};
 use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
 use system::{
-    bindings::{address_space_memory, address_space_stl_le, hwaddr},
-    MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
+    bindings::{address_space_memory, address_space_stl_le},
+    MEMTXATTRS_UNSPECIFIED,
+    prelude::*,
 };
 use util::prelude::*;
 
diff --git a/rust/system/meson.build b/rust/system/meson.build
index 73d61991146..6624fa6cee5 100644
--- a/rust/system/meson.build
+++ b/rust/system/meson.build
@@ -30,6 +30,7 @@ _system_rs = static_library(
       'src/lib.rs',
       'src/bindings.rs',
       'src/memory.rs',
+      'src/prelude.rs',
     ],
     {'.': _system_bindings_inc_rs}
   ),
diff --git a/rust/system/src/lib.rs b/rust/system/src/lib.rs
index aafe9a866c9..5fb83b65d8d 100644
--- a/rust/system/src/lib.rs
+++ b/rust/system/src/lib.rs
@@ -4,3 +4,8 @@
 
 mod memory;
 pub use memory::*;
+
+// preserve one-item-per-"use" syntax, it is clearer
+// for prelude-like modules
+#[rustfmt::skip]
+pub mod prelude;
diff --git a/rust/system/src/prelude.rs b/rust/system/src/prelude.rs
new file mode 100644
index 00000000000..2d98524c36e
--- /dev/null
+++ b/rust/system/src/prelude.rs
@@ -0,0 +1,8 @@
+//! Essential types and traits intended for blanket imports.
+
+// Core memory types
+pub use crate::memory::hwaddr;
+pub use crate::memory::MemoryRegion;
+pub use crate::memory::MemoryRegionOps;
+pub use crate::memory::MemoryRegionOpsBuilder;
+pub use crate::memory::MemTxAttrs;
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 8/8] qom: add more to the prelude
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (6 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 7/8] system: " Paolo Bonzini
@ 2025-11-17  7:42 ` Paolo Bonzini
  2025-11-17  8:03 ` [PATCH 0/8] rust: add preludes to all crates Marc-André Lureau
  8 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  7:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-rust

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/hw/char/pl011/src/device.rs | 2 +-
 rust/hw/core/src/qdev.rs         | 2 +-
 rust/hw/core/src/sysbus.rs       | 2 +-
 rust/hw/core/tests/tests.rs      | 2 +-
 rust/hw/timer/hpet/src/device.rs | 2 +-
 rust/qom/src/prelude.rs          | 4 ++++
 6 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 0b1bb2d5a3b..9f5c4a34df0 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -9,7 +9,7 @@
 use common::prelude::*;
 use hwcore::{prelude::*, ClockEvent, IRQState};
 use migration::{self, prelude::*};
-use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
+use qom::prelude::*;
 use system::prelude::*;
 use util::prelude::*;
 
diff --git a/rust/hw/core/src/qdev.rs b/rust/hw/core/src/qdev.rs
index 4e983da28b7..32370319871 100644
--- a/rust/hw/core/src/qdev.rs
+++ b/rust/hw/core/src/qdev.rs
@@ -12,7 +12,7 @@
 use chardev::Chardev;
 use common::{callbacks::FnCall, Opaque};
 use migration::{impl_vmstate_c_struct, VMStateDescription};
-use qom::{prelude::*, ObjectClass, ObjectImpl, Owned, ParentInit};
+use qom::{prelude::*, ObjectClass};
 use util::{Error, Result};
 
 pub use crate::bindings::{ClockEvent, DeviceClass, Property, ResetType};
diff --git a/rust/hw/core/src/sysbus.rs b/rust/hw/core/src/sysbus.rs
index 68165e89295..c7acf214559 100644
--- a/rust/hw/core/src/sysbus.rs
+++ b/rust/hw/core/src/sysbus.rs
@@ -8,7 +8,7 @@
 
 pub use bindings::SysBusDeviceClass;
 use common::Opaque;
-use qom::{prelude::*, Owned};
+use qom::prelude::*;
 use system::MemoryRegion;
 use util::{Error, Result};
 
diff --git a/rust/hw/core/tests/tests.rs b/rust/hw/core/tests/tests.rs
index e60c9d018f5..115dd7a860d 100644
--- a/rust/hw/core/tests/tests.rs
+++ b/rust/hw/core/tests/tests.rs
@@ -7,7 +7,7 @@
 use bql::prelude::*;
 use hwcore::prelude::*;
 use migration::prelude::*;
-use qom::{prelude::*, ObjectImpl, ParentField};
+use qom::prelude::*;
 use util::bindings::{module_call_init, module_init_type};
 
 // Test that macros can compile.
diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/device.rs
index c5cdb87b073..c82b27ddf15 100644
--- a/rust/hw/timer/hpet/src/device.rs
+++ b/rust/hw/timer/hpet/src/device.rs
@@ -14,7 +14,7 @@
 use common::prelude::*;
 use hwcore::prelude::*;
 use migration::{self, prelude::*};
-use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
+use qom::prelude::*;
 use system::{
     bindings::{address_space_memory, address_space_stl_le},
     MEMTXATTRS_UNSPECIFIED,
diff --git a/rust/qom/src/prelude.rs b/rust/qom/src/prelude.rs
index 00a60959771..6a1ecaef2a7 100644
--- a/rust/qom/src/prelude.rs
+++ b/rust/qom/src/prelude.rs
@@ -6,7 +6,11 @@
 pub use crate::qom::ObjectCast;
 pub use crate::qom::ObjectClassMethods;
 pub use crate::qom::ObjectDeref;
+pub use crate::qom::ObjectImpl;
 pub use crate::qom::ObjectMethods;
 pub use crate::qom::ObjectType;
+pub use crate::qom::Owned;
+pub use crate::qom::ParentField;
+pub use crate::qom::ParentInit;
 
 pub use crate::qom_isa;
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/8] rust: add preludes to all crates
  2025-11-17  7:42 [PATCH 0/8] rust: add preludes to all crates Paolo Bonzini
                   ` (7 preceding siblings ...)
  2025-11-17  7:42 ` [PATCH 8/8] qom: add more to the prelude Paolo Bonzini
@ 2025-11-17  8:03 ` Marc-André Lureau
  2025-11-17  8:36   ` Paolo Bonzini
  8 siblings, 1 reply; 11+ messages in thread
From: Marc-André Lureau @ 2025-11-17  8:03 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, qemu-rust

Hi

On Mon, Nov 17, 2025 at 11:43 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> This series adds a prelude module to all crates, so that
> it becomes possible to import from each crate with either
> of the following
>
>    use XYZ::prelude::*;
>    use XYZ::{self, prelude::*};
>
> The latter is used for items that have a "too common"
> name to be put in the prelude: util::Error, util::Result,
> migration::Infallible.

In my experience, "preludes" are not so ubiquitous (except the std
library). The use of wildcard imports is not encouraged, and may
result in conflicts. Also, it's often subjective what you put there or
not.

I don't think we should encourage it, having explicit import of what
is used is often clearer.

>
> Thanks,
>
> Paolo
>
> Paolo Bonzini (8):
>   util: add prelude
>   common: add prelude
>   hwcore: add prelude
>   migration: add prelude
>   chardev: add prelude
>   bql: add prelude
>   system: add prelude
>   qom: add more to the prelude
>
>  rust/bql/meson.build              |  1 +
>  rust/bql/src/lib.rs               |  5 +++++
>  rust/bql/src/prelude.rs           |  4 ++++
>  rust/chardev/meson.build          |  1 +
>  rust/chardev/src/chardev.rs       |  2 +-
>  rust/chardev/src/lib.rs           |  5 +++++
>  rust/chardev/src/prelude.rs       |  5 +++++
>  rust/common/meson.build           | 13 +------------
>  rust/common/src/lib.rs            |  5 +++++
>  rust/common/src/prelude.rs        |  9 +++++++++
>  rust/hw/char/pl011/src/device.rs  | 22 ++++++++--------------
>  rust/hw/core/meson.build          |  1 +
>  rust/hw/core/src/lib.rs           |  5 +++++
>  rust/hw/core/src/prelude.rs       | 14 ++++++++++++++
>  rust/hw/core/src/qdev.rs          |  2 +-
>  rust/hw/core/src/sysbus.rs        |  2 +-
>  rust/hw/core/tests/tests.rs       |  8 ++++----
>  rust/hw/timer/hpet/src/device.rs  | 26 +++++++++-----------------
>  rust/hw/timer/hpet/src/fw_cfg.rs  |  2 +-
>  rust/migration/meson.build        |  1 +
>  rust/migration/src/lib.rs         |  5 +++++
>  rust/migration/src/migratable.rs  |  2 +-
>  rust/migration/src/prelude.rs     | 19 +++++++++++++++++++
>  rust/qom/src/prelude.rs           |  4 ++++
>  rust/system/meson.build           |  1 +
>  rust/system/src/lib.rs            |  5 +++++
>  rust/system/src/prelude.rs        |  8 ++++++++
>  rust/tests/tests/vmstate_tests.rs |  7 +++----
>  rust/util/meson.build             |  1 +
>  rust/util/src/lib.rs              |  5 +++++
>  rust/util/src/prelude.rs          | 11 +++++++++++
>  31 files changed, 145 insertions(+), 56 deletions(-)
>  create mode 100644 rust/bql/src/prelude.rs
>  create mode 100644 rust/chardev/src/prelude.rs
>  create mode 100644 rust/common/src/prelude.rs
>  create mode 100644 rust/hw/core/src/prelude.rs
>  create mode 100644 rust/migration/src/prelude.rs
>  create mode 100644 rust/system/src/prelude.rs
>  create mode 100644 rust/util/src/prelude.rs
>
> --
> 2.51.1
>
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/8] rust: add preludes to all crates
  2025-11-17  8:03 ` [PATCH 0/8] rust: add preludes to all crates Marc-André Lureau
@ 2025-11-17  8:36   ` Paolo Bonzini
  0 siblings, 0 replies; 11+ messages in thread
From: Paolo Bonzini @ 2025-11-17  8:36 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, qemu-rust

On Mon, Nov 17, 2025 at 9:03 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Mon, Nov 17, 2025 at 11:43 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
> >
> > This series adds a prelude module to all crates, so that
> > it becomes possible to import from each crate with either
> > of the following
> >
> >    use XYZ::prelude::*;
> >    use XYZ::{self, prelude::*};
> >
> > The latter is used for items that have a "too common"
> > name to be put in the prelude: util::Error, util::Result,
> > migration::Infallible.
>
> In my experience, "preludes" are not so ubiquitous (except the std
> library). The use of wildcard imports is not encouraged, and may
> result in conflicts.

Yes, I agree with this.  On the other hand, we already have lists of
imports that are two-three lines long and I'm afraid that people would
prefer to just import migration::* for example.  While we can block
them with -Dclippy::wildcard_imports, the problem is real.

So I was a bit undecided and went looking for examples of crates that
do have a prelude. I first noticed that bevy has a similar system,
with each of its crates providing a prelude.  IMO QEMU is a similar
case to bevy, where most of the code will use structs from the QEMU
crates more than std, so it makes sense to have them. Futures and
Tokio also have a prelude, and they also fit the idea of crates that
provide a programming environment.

Preludes let you import libraries with a level of detail similar to C
includes.  For simple library crates that offer two-three types it's
not necessary to have one, but as the complexity and number of crates
increase, they provide more clarity.

Another thing to notice is that the QOM bindings work a lot with
extension traits implemented on all types.  There should be no need
for users to know the difference between DeviceState, DeviceMethods
and DeviceClassMethods. Preludes help with that.

> Also, it's often subjective what you put there or not.

Right - for now I just defined what should *never* be in a prelude:
the rule was simply "do not include anything that can conflict with
std".  This should not be that bad, otherwise we'd have similar
problems with C includes as mentioned above.

Another thing that should not be in the preludes without extremely
good reasons is enum variants; Ok/Err and Some/None are the only
exceptions in the standard library prelude, and they should probably
remain the only ones.

Paolo



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-11-17  8:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/8] common: " Paolo Bonzini
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

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).