Skip to content

Commit

Permalink
Document ::std::mem
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Apr 3, 2023
1 parent 4a0704a commit e7d193e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/rune/src/modules/mem.rs
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(())
}

0 comments on commit e7d193e

Please sign in to comment.