pub struct ThisPointerTracker { /* private fields */ }Expand description
Tracks the state of member fields within a method based on ‘this’ pointer semantics
Enforces Rust-like rules:
- Const methods (&self): Can read fields, cannot modify or move
- Non-const methods (&mut self): Can read and modify fields, CANNOT move fields
- Rvalue methods (self): Can do anything including moving fields
Implementations§
Source§impl ThisPointerTracker
impl ThisPointerTracker
Sourcepub fn new(method_qualifier: Option<MethodQualifier>) -> Self
pub fn new(method_qualifier: Option<MethodQualifier>) -> Self
Create a new tracker for a method with the given qualifier
Sourcepub fn can_read_member(&self, field: &str) -> Result<(), String>
pub fn can_read_member(&self, field: &str) -> Result<(), String>
Check if we can read a member field
Rules:
- All method types can read fields (const, non-const, &&)
- Cannot read moved fields
Sourcepub fn can_modify_member(&self, field: &str) -> Result<(), String>
pub fn can_modify_member(&self, field: &str) -> Result<(), String>
Check if we can modify a member field
Rules:
- Const methods (&self): CANNOT modify
- Non-const methods (&mut self): CAN modify
- Rvalue methods (self): CAN modify
- Cannot modify moved fields
- Cannot modify immutably borrowed fields
Sourcepub fn can_move_member(&self, field: &str) -> Result<(), String>
pub fn can_move_member(&self, field: &str) -> Result<(), String>
Check if we can move a member field
Rules:
- Const methods (&self): CANNOT move
- Non-const methods (&mut self): CANNOT move (key Rust restriction!)
- Rvalue methods (self): CAN move
- Cannot move already-moved fields
- Cannot move borrowed fields
Sourcepub fn can_borrow_member(
&self,
field: &str,
kind: BorrowKind,
) -> Result<(), String>
pub fn can_borrow_member( &self, field: &str, kind: BorrowKind, ) -> Result<(), String>
Check if we can borrow a member field
Rules:
- Const methods: Can only create immutable borrows
- Non-const methods: Can create mutable or immutable borrows
- Rvalue methods: Can create any borrow
- Cannot borrow moved fields
- Respect existing borrows (no mutable + immutable, no multiple mutable)
Sourcepub fn mark_field_moved(&mut self, field: String)
pub fn mark_field_moved(&mut self, field: String)
Mark a field as moved
Sourcepub fn mark_field_borrowed(&mut self, field: String, kind: BorrowKind)
pub fn mark_field_borrowed(&mut self, field: String, kind: BorrowKind)
Mark a field as borrowed
Sourcepub fn clear_field_borrow(&mut self, field: &str)
pub fn clear_field_borrow(&mut self, field: &str)
Clear a borrow on a field (when reference goes out of scope)
Sourcepub fn method_qualifier(&self) -> Option<&MethodQualifier>
pub fn method_qualifier(&self) -> Option<&MethodQualifier>
Get the method qualifier
Sourcepub fn is_field_moved(&self, field: &str) -> bool
pub fn is_field_moved(&self, field: &str) -> bool
Check if a field has been moved
Sourcepub fn is_field_borrowed(&self, field: &str) -> bool
pub fn is_field_borrowed(&self, field: &str) -> bool
Check if a field is currently borrowed
Trait Implementations§
Source§impl Clone for ThisPointerTracker
impl Clone for ThisPointerTracker
Source§fn clone(&self) -> ThisPointerTracker
fn clone(&self) -> ThisPointerTracker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ThisPointerTracker
impl RefUnwindSafe for ThisPointerTracker
impl Send for ThisPointerTracker
impl Sync for ThisPointerTracker
impl Unpin for ThisPointerTracker
impl UnwindSafe for ThisPointerTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more