ThisPointerTracker

Struct ThisPointerTracker 

Source
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

Source

pub fn new(method_qualifier: Option<MethodQualifier>) -> Self

Create a new tracker for a method with the given qualifier

Source

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
Source

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
Source

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
Source

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)
Source

pub fn mark_field_moved(&mut self, field: String)

Mark a field as moved

Source

pub fn mark_field_borrowed(&mut self, field: String, kind: BorrowKind)

Mark a field as borrowed

Source

pub fn clear_field_borrow(&mut self, field: &str)

Clear a borrow on a field (when reference goes out of scope)

Source

pub fn method_qualifier(&self) -> Option<&MethodQualifier>

Get the method qualifier

Source

pub fn is_field_moved(&self, field: &str) -> bool

Check if a field has been moved

Source

pub fn is_field_borrowed(&self, field: &str) -> bool

Check if a field is currently borrowed

Trait Implementations§

Source§

impl Clone for ThisPointerTracker

Source§

fn clone(&self) -> ThisPointerTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ThisPointerTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.