Context:
PR #119 removes the 'info lifetime from #[derive(Accounts)] structs by making account fields owned. However, #[account] state types with dynamic fields (String, Vec, tail) still require a lifetime parameter:
// Current — lifetime required for dynamic fields
#[account(discriminator = 1)]
pub struct Profile<'a> {
pub owner: Address,
pub name: String<u32, 32>,
pub tags: Vec<Address, u32, 10>,
}
// This forces Accounts structs to carry the lifetime too:
#[derive(Accounts)]
pub struct UpdateProfile<'profile> {
pub user: Signer,
pub profile: Account<Profile<'profile>>,
}
Proposal:
Make the dynamic #[account] type own its AccountView instead of holding &'a mut AccountView, eliminating the lifetime:
// After — no lifetime
#[account(discriminator = 1)]
pub struct Profile {
pub owner: Address,
pub name: String<u32, 32>,
pub tags: Vec<Address, u32, 10>,
}
#[derive(Accounts)]
pub struct UpdateProfile {
pub user: Signer,
pub profile: Account<Profile>,
}
Why this is safe:
Dynamic field accessors (name(), signers()) don't store references — they construct &str / &[T] on each call from the raw data pointer, bounded by &self. The lifetime on the state struct was only there because it held &'a mut AccountView. With an owned AccountView, the accessors work identically. The Inner struct (for set_inner) keeps its own method-scoped lifetime for borrowed &str/&[T] parameters.
Changes needed:
derive/src/account/dynamic.rs — struct owns AccountView, from_account_view uses ptr::read
derive/src/account/accessors.rs — &*self.__view → &self.__view
derive/src/account/mod.rs — remove lifetime requirement check
Context:
PR #119 removes the
'infolifetime from#[derive(Accounts)]structs by making account fields owned. However,#[account]state types with dynamic fields (String,Vec, tail) still require a lifetime parameter:Proposal:
Make the dynamic
#[account]type own itsAccountViewinstead of holding&'a mut AccountView, eliminating the lifetime:Why this is safe:
Dynamic field accessors (
name(),signers()) don't store references — they construct&str/&[T]on each call from the raw data pointer, bounded by&self. The lifetime on the state struct was only there because it held&'a mut AccountView. With an ownedAccountView, the accessors work identically. TheInnerstruct (forset_inner) keeps its own method-scoped lifetime for borrowed&str/&[T]parameters.Changes needed:
derive/src/account/dynamic.rs— struct ownsAccountView,from_account_viewusesptr::readderive/src/account/accessors.rs—&*self.__view→&self.__viewderive/src/account/mod.rs— remove lifetime requirement check