pub struct Resource {
pub name: String,
pub ty: LinearType,
pub ownership: Ownership,
pub use_count: usize,
pub created_at: Option<String>,
pub last_used_at: Option<String>,
}Expand description
A resource tracked by the linear type system.
Fields§
§name: StringResource name/identifier
ty: LinearTypeResource type
ownership: OwnershipCurrent ownership state
use_count: usizeNumber of times the resource has been used
created_at: Option<String>Location where the resource was created
last_used_at: Option<String>Location where the resource was last used
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn new(name: impl Into<String>, ty: LinearType) -> Self
pub fn new(name: impl Into<String>, ty: LinearType) -> Self
Create a new owned resource.
Sourcepub fn with_created_at(self, location: impl Into<String>) -> Self
pub fn with_created_at(self, location: impl Into<String>) -> Self
Set the creation location.
Sourcepub fn use_resource(
&mut self,
location: impl Into<String>,
) -> Result<(), LinearError>
pub fn use_resource( &mut self, location: impl Into<String>, ) -> Result<(), LinearError>
Use the resource, returning an error if not allowed.
Sourcepub fn move_to(
&mut self,
location: impl Into<String>,
) -> Result<(), LinearError>
pub fn move_to( &mut self, location: impl Into<String>, ) -> Result<(), LinearError>
Move the resource to a new owner.
Sourcepub fn drop_resource(&mut self) -> Result<(), LinearError>
pub fn drop_resource(&mut self) -> Result<(), LinearError>
Drop the resource.
Sourcepub fn validate_end_of_scope(&self) -> Result<(), LinearError>
pub fn validate_end_of_scope(&self) -> Result<(), LinearError>
Validate the resource state at the end of its scope.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Resource
impl RefUnwindSafe for Resource
impl Send for Resource
impl Sync for Resource
impl Unpin for Resource
impl UnwindSafe for Resource
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