summaryrefslogtreecommitdiff
path: root/src/library/extend.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/extend.rs')
-rw-r--r--src/library/extend.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/library/extend.rs b/src/library/extend.rs
index 6396274e..cf69dbd0 100644
--- a/src/library/extend.rs
+++ b/src/library/extend.rs
@@ -1,4 +1,5 @@
use crate::prelude::*;
+use crate::pretty::pretty;
/// `type`: Find out the name of a value's type.
///
@@ -8,9 +9,22 @@ use crate::prelude::*;
/// # Return value
/// The name of the value's type as a string.
pub fn type_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
- if let Some(value) = args.require::<Value>(ctx, "value") {
- value.type_name().into()
- } else {
- Value::Error
+ match args.require::<Value>(ctx, "value") {
+ Some(value) => value.type_name().into(),
+ None => Value::Error,
+ }
+}
+
+/// `repr`: Get the string representation of a value.
+///
+/// # Positional arguments
+/// - Any value.
+///
+/// # Return value
+/// The string representation of the value.
+pub fn repr(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
+ match args.require::<Value>(ctx, "value") {
+ Some(value) => pretty(&value).into(),
+ None => Value::Error,
}
}