Skip to content

Commit 3f3b9d4

Browse files
committed
Improve string.inspect documentation
1 parent 86cec7a commit 3f3b9d4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/gleam/string.gleam

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,28 @@ pub fn capitalise(string: String) -> String {
829829

830830
/// Returns a `String` representation of a term in Gleam syntax.
831831
///
832+
/// This may be occasionally useful for quick-and-dirty printing of values in
833+
/// scripts. For error reporting and other uses prefer constructing strings by
834+
/// pattern matching on the values.
835+
///
836+
/// ## Limitations
837+
///
838+
/// The output format of this function is not stable and could change at any
839+
/// time. The output is not suitable for parsing.
840+
///
841+
/// This function works using runtime reflection, so the output may not be
842+
/// perfectly accurate for data structures where the runtime structure doesn't
843+
/// hold enough information to determine the original syntax. For example,
844+
/// tuples with an Erlang atom in the first position will be mistaken for Gleam
845+
/// records.
846+
///
847+
/// ## Security and safety
848+
///
849+
/// There is no limit to how large the strings that this function can produce.
850+
/// Be careful not to call this function with large data structures or you
851+
/// could use very large amounts of memory, potentially causing runtime
852+
/// problems.
853+
///
832854
pub fn inspect(term: anything) -> String {
833855
do_inspect(term)
834856
|> string_tree.to_string

0 commit comments

Comments
 (0)