-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
//! The `std::mem` module. | ||
use crate as rune; | ||
use crate::runtime::{Value, VmError}; | ||
use crate::{ContextError, Module}; | ||
|
||
/// Construct the `std` module. | ||
pub fn module() -> Result<Module, ContextError> { | ||
let mut module = Module::with_crate_item("std", ["mem"]); | ||
module.function(["drop"], drop_impl)?; | ||
module.function_meta(drop)?; | ||
Ok(module) | ||
} | ||
|
||
fn drop_impl(value: Value) -> Result<(), VmError> { | ||
#[rune::function] | ||
/// Explicitly drop the given value, freeing up any memory associated with it. | ||
/// | ||
/// Normally values are dropped as they go out of scope, but with this method it | ||
/// can be explicitly controlled instead. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Basic usage: | ||
/// | ||
/// ```rune | ||
/// let v = [1, 2, 3]; | ||
/// drop(v); | ||
/// ``` | ||
fn drop(value: Value) -> Result<(), VmError> { | ||
value.take()?; | ||
Ok(()) | ||
} |