Inspect.Algebra.string

You're seeing just the function string, go back to Inspect.Algebra module for more information.
Link to this function

string(string)

View Source (since 1.6.0)

Specs

string(String.t()) :: doc_string()

Creates a document represented by string.

While Inspect.Algebra accepts binaries as documents, those are counted by binary size. On the other hand, string documents are measured in terms of graphemes towards the document size.

Examples

The following document has 10 bytes and therefore it does not format to width 9 without breaks:

iex> doc = Inspect.Algebra.glue("olá", " ", "mundo")
iex> doc = Inspect.Algebra.group(doc)
iex> Inspect.Algebra.format(doc, 9)
["olá", "\n", "mundo"]

However, if we use string, then the string length is used, instead of byte size, correctly fitting:

iex> string = Inspect.Algebra.string("olá")
iex> doc = Inspect.Algebra.glue(string, " ", "mundo")
iex> doc = Inspect.Algebra.group(doc)
iex> Inspect.Algebra.format(doc, 9)
["olá", " ", "mundo"]