doc: add documentation for catalog.for_each and catalog.for_each_mut

This commit is contained in:
2025-11-11 16:31:26 +01:00
parent 34808ccf74
commit e9b136341b
2 changed files with 34 additions and 0 deletions

View File

@@ -1,6 +1,23 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Iterates over each item in the catalog that can be converted into type `T` and applies a predicate function.
///
/// This method allows read-only iteration over entities. The predicate receives an immutable reference
/// to the item.
///
/// # Type Parameters
///
/// * `T`: The target type that entities should be converted into. Must implement `EAV`.
/// * `F`: The type of the predicate function.
///
/// # Arguments
///
/// * `predicate`: A mutable closure that takes an immutable reference to an item of type `T`.
///
/// # Returns
///
/// A `Result` indicating success (`Ok(())`) or failure (`Err(FailedTo)`).
pub fn for_each<T, F>(&self, mut predicate: F) -> Result<(), FailedTo> pub fn for_each<T, F>(&self, mut predicate: F) -> Result<(), FailedTo>
where where
T: EAV, T: EAV,

View File

@@ -1,6 +1,23 @@
use crate::*; use crate::*;
impl Catalog { impl Catalog {
/// Iterates over each item in the catalog that can be converted into type `T` and applies a mutable predicate function.
///
/// This method allows mutable iteration over entities. If the item is modified by the predicate,
/// its state in the catalog will be marked as `EntityState::Updated`.
///
/// # Type Parameters
///
/// * `T`: The target type that entities should be converted into. Must implement `EAV`.
/// * `F`: The type of the predicate function.
///
/// # Arguments
///
/// * `predicate`: A mutable closure that takes a mutable reference to an item of type `T` and returns a `Result<(), Box<dyn error::Error>>`. If the predicate returns an `Err`, it will be mapped to `FailedTo::ExecutePredicate`.
///
/// # Returns
///
/// A `Result` indicating success (`Ok(())`) or failure (`Err(FailedTo)`).
pub fn for_each_mut<T, F>(&self, mut predicate: F) -> Result<(), FailedTo> pub fn for_each_mut<T, F>(&self, mut predicate: F) -> Result<(), FailedTo>
where where
T: EAV, T: EAV,