[Issue 24049] New: std.conv.to: string to enum conversion is not documented

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 19 00:22:17 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24049

          Issue ID: 24049
           Summary: std.conv.to: string to enum conversion is not
                    documented
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

std.conv.to supports conversion between enum types and string in both
directions:

---
import std.conv: to;

enum Example { foo }

unittest
{
    assert(Example.foo.to!string == "foo");
    assert("foo".to!Example == Example.foo);
}
---

However, only the enum-to-string conversion is mentioned in std.conv.to's
documentation:

> Stringize conversion from all types is supported.
> [...]
> * Enumerated types are converted to strings as their symbolic names.

The conversion in the other direction, from string to enum type, is only
mentioned in the documentation for std.conv.parse, where users of std.conv.to
are likely to miss it.

--


More information about the Digitalmars-d-bugs mailing list