Skip to content

Commit 8a6f286

Browse files
committed
Add invariant details
1 parent 7ccb7ba commit 8a6f286

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

sdk/pinocchio/src/account_info.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ pub enum BorrowState {
4141

4242
/// Raw account data.
4343
///
44-
/// This data is wrapped in an `AccountInfo` struct, which provides safe access
45-
/// to the data.
44+
/// This struct is wrapped by [`AccountInfo`], which provides safe access
45+
/// to account information. At runtime, the account's data is serialized
46+
/// directly after the [`Account`] struct in memory, with its size specified
47+
/// by [`Account::data_len`].
4648
#[repr(C)]
4749
#[derive(Clone, Copy, Default)]
4850
pub(crate) struct Account {
@@ -112,9 +114,20 @@ pub(crate) struct Account {
112114

113115
/// Wrapper struct for an `Account`.
114116
///
115-
/// This struct provides safe access to the data in an `Account`. It is also
116-
/// used to track borrows of the account data and lamports, given that an
117-
/// account can be "shared" across multiple `AccountInfo` instances.
117+
/// This struct provides safe access to the data in an `Account`. It is
118+
/// also used to track borrows of the account data and lamports, given
119+
/// that an account can be "shared" across multiple `AccountInfo`
120+
/// instances.
121+
///
122+
/// # Invariants
123+
///
124+
/// - The `raw` pointer must be valid and point to memory containing an
125+
/// [`Account`] struct, immediately followed by the account's data region.
126+
/// - The length of the account data must exactly match the value stored in
127+
/// [`Account::data_len`].
128+
///
129+
/// These conditions must always hold for any `AccountInfo` created from
130+
/// a raw pointer.
118131
#[repr(C)]
119132
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
120133
pub struct AccountInfo {

0 commit comments

Comments
 (0)