carbon_core/
account_utils.rs

1use solana_instruction::AccountMeta;
2use solana_pubkey::Pubkey;
3
4/// Returns the next account's pubkey from the iterator, or `None` if there are no more accounts.
5///
6/// # Usage
7/// - Use with `?` to indicate the account is required:
8///   ```ignore
9///   let required = next_account(&mut iter)?;
10///   ```
11///   This will propagate `None` if the account is missing.
12/// - Use without `?` to handle optional accounts:
13///   ```ignore
14///   let optional = next_account(&mut iter);
15///   ```
16///   This returns `Option<Pubkey>` that you can match or use directly.
17///
18/// # Example
19/// ```ignore
20/// let mut iter = accounts.iter();
21/// let required = next_account(&mut iter)?;           // required account
22/// let optional = next_account(&mut iter);            // optional account
23/// ```
24pub fn next_account<'a>(iter: &mut impl Iterator<Item = &'a AccountMeta>) -> Option<Pubkey> {
25    Some(iter.next()?.pubkey)
26}