/// Returns a `RefMut` to the account data structure for reading or writing.
/// Should only be called once, when the account is being initialized.
Returns a `RefMut` to the account data structure for reading or writing.
Should only be called once, when the account is being initialized.
Returns a ` RefMut ` to the account data structure for reading or writing . Should only be called once when the account is being initialized .
pub fn load_init(&self) -> Result<RefMut<T>, ProgramError> {
        // AccountInfo api allows you to borrow mut even if the account isn't
        // writable, so add this check for a better dev experience.
        if !self.acc_info.is_writable {
            return Err(ErrorCode::AccountNotMutable.into());
        }
        let data = self.acc_info.try_borrow_mut_data()?;
        // The discriminator should be zero, since we're initializing.
        let mut disc_bytes = [0u8; 8];
        disc_bytes.copy_from_slice(&data[..8]);
        let discriminator = u64::from_le_bytes(disc_bytes);
        if discriminator != 0 {
            return Err(ErrorCode::AccountDiscriminatorAlreadySet.into());
        }
        Ok(RefMut::map(data, |data| {
            bytemuck::from_bytes_mut(&mut data.deref_mut()[8..])
        }))
    }
pub fn load_init ( & self ) -> Result < RefMut < T > , ProgramError > { // AccountInfo api allows you to borrow mut even if the account isn't // writable, so add this check for a better dev experience. if ! self . acc_info . is_writable { return Err ( ErrorCode :: AccountNotMutable . into ( ) ) ; } let data = self . acc_info . try_borrow_mut_data ( ) ? ; // The discriminator should be zero, since we're initializing. let mut disc_bytes = [ 0u8 ; 8 ] ; disc_bytes . copy_from_slice ( & data [ .. 8 ] ) ; let discriminator = u64 :: from_le_bytes ( disc_bytes ) ; if discriminator != 0 { return Err ( ErrorCode :: AccountDiscriminatorAlreadySet . into ( ) ) ; } Ok ( RefMut :: map ( data , | data | { bytemuck :: from_bytes_mut ( & mut data . deref_mut ( ) [ 8 .. ] ) } ) ) }
Returns a `RefMut` to the account data structure for reading or writing.
Returns a ` RefMut ` to the account data structure for reading or writing .
&self