summaryrefslogtreecommitdiff
path: root/src/library/extend.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-18 14:17:20 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-18 15:06:13 +0100
commited81049ddc8fcef3ddf6f6f69d95bb52512bf698 (patch)
tree5ee2e955b4fa50bc536d215577a0321c9b4c6617 /src/library/extend.rs
parentcc964e32c993e9446896f8a75731783108866ce8 (diff)
Show repr in monospace 📏
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,
}
}