use super::FakeHost;
use super::Installed;
use super::table;
use crate::abi::Header;
use crate::abi::InventoryOp;
use crate::abi::InventoryOpResult;
use crate::abi::InventoryResult;
impl FakeHost {
#[must_use]
pub fn without_inventories(mut self) -> Self {
self.no_inventories = true;
self
}
}
#[expect(
clippy::unused_self,
reason = "the fake's state is process-wide; `self` proves it is installed"
)]
impl Installed {
#[must_use]
pub fn inventory_requests(&self) -> Vec<SubmittedRequest> {
table::with(Vec::new(), |s| {
s.inventory_requests
.iter()
.map(|r| r.request.clone())
.collect()
})
}
#[must_use = "false means no request was open"]
pub fn finish_inventory(&self, outcome: u32, ops: &[InventoryOpResult]) -> bool {
let open = table::with(None, |s| {
(!s.inventory_requests.is_empty()).then(|| s.inventory_requests.remove(0))
});
let Some(open) = open else {
return false;
};
let result = InventoryResult {
header: Header::of::<InventoryResult>(),
outcome,
op_count: u32::try_from(ops.len()).unwrap_or(0),
ops: ops.as_ptr(),
};
unsafe {
(open.done)(
&raw const result,
core::ptr::with_exposed_provenance_mut(open.user),
);
}
true
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct SubmittedRequest {
pub ops: Vec<InventoryOp>,
pub flags: u32,
pub actor: u32,
}