oct 0.26.0

Octonary transcodings.
Documentation
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This Source Code Form is subject to the terms of
// the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, you
// can obtain one at:
// <https://mozilla.org/MPL/2.0/>.

//! Tests for [`IntoOcts`].

#![cfg(all(test, miri))]

use core::ptr;
use oct::{Immutable, Init, IntoOcts};

#[repr(C)]
struct Foo(
	pub u64,
	pub u32,
	pub u32,
	pub u16,
	pub u16,
	pub u16,
	pub u16,
	pub u8,
	pub u8,
	pub u8,
	pub u8,
	pub u8,
	pub u8,
	pub u8,
	pub u8,
);

unsafe impl Immutable for Foo {}

unsafe impl Init for Foo {}

#[test]
fn test_foo_as_octs() {
	assert_eq!(
		size_of::<Foo>(),
		32,
	);

	static DATA: &Foo = &Foo(
		u64::from_be(0x1F_1E_1D_1C_1B_1A_19_18),
		u32::from_be(0x17_16_15_14),
		u32::from_be(0x13_12_11_10),
		u16::from_be(0x0F_0E),
		u16::from_be(0x0D_0C),
		u16::from_be(0x0B_0A),
		u16::from_be(0x09_08),
		u8::from_be(0x07),
		u8::from_be(0x06),
		u8::from_be(0x05),
		u8::from_be(0x04),
		u8::from_be(0x03),
		u8::from_be(0x02),
		u8::from_be(0x01),
		u8::from_be(0x00),
	);

	let octs = DATA.as_octs();

	assert_eq!(
		octs.len(),
		size_of_val(DATA),
	);

	assert_eq!(
		octs.as_ptr().addr(),
		ptr::from_ref(DATA).addr(),
	);

	assert_eq!(
		octs,
		&[
			0x1F,
			0x1E,
			0x1D,
			0x1C,
			0x1B,
			0x1A,
			0x19,
			0x18,
			0x17,
			0x16,
			0x15,
			0x14,
			0x13,
			0x12,
			0x11,
			0x10,
			0x0F,
			0x0E,
			0x0D,
			0x0C,
			0x0B,
			0x0A,
			0x09,
			0x08,
			0x07,
			0x06,
			0x05,
			0x04,
			0x03,
			0x02,
			0x01,
			0x00,
		],
	);
}