#![allow(clippy::uninlined_format_args)] #![allow(unused_imports)] //! The integration tests seem to always have `std` linked, so things that would //! depend on that can go here.
use bytemuck::*; use core::num::NonZeroU8;
#[test] fn test_transparent_vtabled() { use core::fmt::Display;
#[test] #[cfg(feature = "extern_crate_alloc")] fn test_try_from_box_bytes() { // Different layout: target alignment is greater than source alignment.
assert_eq!(
try_from_box_bytes::<u32>(Box::new([0u8; 4]).into()).map_err(|(x, _)| x),
Err(PodCastError::AlignmentMismatch)
);
// Different layout: target alignment is less than source alignment.
assert_eq!(
try_from_box_bytes::<u32>(Box::new(0u64).into()).map_err(|(x, _)| x),
Err(PodCastError::AlignmentMismatch)
);
// Different layout: target size is greater than source size.
assert_eq!(
try_from_box_bytes::<[u32; 2]>(Box::new(0u32).into()).map_err(|(x, _)| x),
Err(PodCastError::SizeMismatch)
);
// Different layout: target size is less than source size.
assert_eq!(
try_from_box_bytes::<u32>(Box::new([0u32; 2]).into()).map_err(|(x, _)| x),
Err(PodCastError::SizeMismatch)
);
// Round trip: alignment is equal to size.
assert_eq!(*from_box_bytes::<u32>(Box::new(1000u32).into()), 1000u32);
// Round trip: alignment is divider of size.
assert_eq!(&*from_box_bytes::<[u8; 5]>(Box::new(*b"hello").into()), b"hello");
// It's ok for T to have uninitialized bytes. #[cfg(feature = "derive")]
{ #[derive(Debug, Copy, Clone, PartialEq, Eq, AnyBitPattern)] struct Foo(u8, u16);
assert_eq!(
*from_box_bytes::<Foo>(Box::new([0xc5c5u16; 2]).into()),
Foo(0xc5u8, 0xc5c5u16)
);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.