Documentation
use super::captured::*;

//
// Attachments
//

/// Access to attachments.
pub trait Attachments {
    /// Iterate attachments.
    fn attachments(&self) -> impl Iterator<Item = &CapturedAttachment>;

    /// Iterate attachments of a type.
    fn attachments_of_type<'this, AttachmentT>(
        &'this self,
    ) -> impl Iterator<Item = &'this AttachmentT>
    where
        AttachmentT: 'static,
    {
        self.attachments()
            .filter_map(|attachment| attachment.downcast_ref())
    }

    /// First attachment of a type.
    fn attachment_of_type<AttachmentT>(&self) -> Option<&AttachmentT>
    where
        AttachmentT: 'static,
    {
        self.attachments_of_type().next()
    }
}