Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions magicblock-magic-program-api/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ pub struct ActionArgs {
pub data: Vec<u8>,
}

impl ActionArgs {
pub fn default(data: Vec<u8>) -> Self {
Self {
escrow_index: 255,
data,
}
}
pub fn escrow_index(&self) -> u8 {
self.escrow_index
}

pub fn data(&self) -> &Vec<u8> {
&self.data
}
Comment on lines +26 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Return &[u8] instead of &Vec<u8> for idiomatic Rust.

Returning &Vec<u8> is considered an anti-pattern in Rust because it exposes the implementation detail and limits flexibility. Instead, return &[u8], which works with vectors, arrays, and slices. Callers can still obtain &Vec<u8> via deref coercion if needed.

Apply this diff:

-    pub fn data(&self) -> &Vec<u8> {
-        &self.data
+    pub fn data(&self) -> &[u8] {
+        &self.data
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn data(&self) -> &Vec<u8> {
&self.data
}
pub fn data(&self) -> &[u8] {
&self.data
}
🤖 Prompt for AI Agents
In magicblock-magic-program-api/src/args.rs around lines 26 to 28, the accessor
currently returns &Vec<u8> which leaks the implementation; change the method
signature to return a slice (&[u8]) instead and return a slice of the vector
(e.g., via as_slice() or a full-range slice) so callers get a &[u8] while the
internal field remains Vec<u8>.


pub fn with_escrow_index(mut self, index: u8) -> Self {
self.escrow_index = index;
self
}
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct BaseActionArgs {
pub args: ActionArgs,
Expand Down
Loading