diff options
| author | Benno Lossin <benno.lossin@proton.me> | 2025-05-23 14:54:11 +0200 |
|---|---|---|
| committer | Benno Lossin <lossin@kernel.org> | 2025-06-11 21:13:56 +0200 |
| commit | 58cebd68882edd407c7f65ebb4a42034bc1ffc6d (patch) | |
| tree | 45091b6a2622f9130b7aa0830d1c5dc3bf44be15 /rust/pin-init/examples/big_struct_in_place.rs | |
| parent | e832374ccadf4d1ce7bd40a85b9320bd7fbb3628 (diff) | |
rust: pin-init: examples, tests: add conditional compilation in order to compile under any feature combination
In the CI, all examples & tests should be run under all feature
combinations. Currently several examples & tests use `std` without
conditionally enabling it. Thus make them all compile under any feature
combination by conditionally disabling the code that uses e.g. `std`.
Link: https://github.com/Rust-for-Linux/pin-init/pull/50/commits/fdfb70efddbc711b4543c850ee38a2f5a8d17cb6
Link: https://lore.kernel.org/all/20250523125424.192843-2-lossin@kernel.org
Signed-off-by: Benno Lossin <lossin@kernel.org>
Diffstat (limited to 'rust/pin-init/examples/big_struct_in_place.rs')
| -rw-r--r-- | rust/pin-init/examples/big_struct_in_place.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/rust/pin-init/examples/big_struct_in_place.rs b/rust/pin-init/examples/big_struct_in_place.rs index 30d44a334ffd..b0ee793a0a0c 100644 --- a/rust/pin-init/examples/big_struct_in_place.rs +++ b/rust/pin-init/examples/big_struct_in_place.rs @@ -4,6 +4,7 @@ use pin_init::*; // Struct with size over 1GiB #[derive(Debug)] +#[allow(dead_code)] pub struct BigStruct { buf: [u8; 1024 * 1024 * 1024], a: u64, @@ -25,15 +26,18 @@ impl ManagedBuf { } fn main() { - // we want to initialize the struct in-place, otherwise we would get a stackoverflow - let buf: Box<BigStruct> = Box::init(init!(BigStruct { - buf <- zeroed(), - a: 7, - b: 186, - c: 7789, - d: 34, - managed_buf <- ManagedBuf::new(), - })) - .unwrap(); - println!("{}", core::mem::size_of_val(&*buf)); + #[cfg(any(feature = "std", feature = "alloc"))] + { + // we want to initialize the struct in-place, otherwise we would get a stackoverflow + let buf: Box<BigStruct> = Box::init(init!(BigStruct { + buf <- zeroed(), + a: 7, + b: 186, + c: 7789, + d: 34, + managed_buf <- ManagedBuf::new(), + })) + .unwrap(); + println!("{}", core::mem::size_of_val(&*buf)); + } } |