Stream: beginners

Topic: Shouldn't `from_interpolation` return a `Try`?


view this post on Zulip Aurélien Geron (Oct 03 2026 at 08:35):

from_quote and from_numeral return a Try, but not from_interpolation. What if the function detects that the format is incorrect? Should it crash? Or am I missing something?

view this post on Zulip Aurélien Geron (Oct 03 2026 at 10:05):

Btw, I just submitted PR #299 for a code example showing how to create custom literals.

view this post on Zulip Anton (Oct 03 2026 at 10:40):

Aurélien Geron said:

from_quote and from_numeral return a Try, but not from_interpolation. What if the function detects that the format is incorrect? Should it crash? Or am I missing something?

You can choose the return type, so you can make it a Try if you want.

view this post on Zulip Anton (Oct 03 2026 at 12:03):

so you can make it a Try if you want.

Should I wait to merge the examples PR so that can be shown as well?

view this post on Zulip Richard Feldman (Oct 03 2026 at 13:40):

oh yeah we should change this

view this post on Zulip Richard Feldman (Oct 03 2026 at 13:41):

from_interpolation is one of the special ones that gets called at compile time

view this post on Zulip Richard Feldman (Oct 03 2026 at 13:41):

like from_quote

view this post on Zulip Richard Feldman (Oct 03 2026 at 13:41):

if you want to make a type that can be built from string interpolation literals

view this post on Zulip Richard Feldman (Oct 03 2026 at 13:42):

and yeah it should be a Try - can you open an issue for that @Aurélien Geron?

view this post on Zulip Aurélien Geron (Oct 03 2026 at 20:02):

I'm confused, @Richard Feldman : @Anton says we can choose the return type, so it can be a Try if we want to, so why do we need to open an issue?
Btw, what if from_quote or from_numeral can never fail? Should we return Try(Foo, {})?

view this post on Zulip Aurélien Geron (Oct 03 2026 at 20:03):

Anton said:

Should I wait to merge the examples PR so that can be shown as well?

Yes, I'll update the example asap. :+1:

view this post on Zulip Richard Feldman (Oct 03 2026 at 20:03):

it's better to return Try(Foo, _a)

view this post on Zulip Richard Feldman (Oct 03 2026 at 20:04):

then you can do the Ok(foo) = ... trick on it

view this post on Zulip Richard Feldman (Oct 03 2026 at 20:05):

we need an issue for the compiler side of it - to teach the compiler to expect a Try and give a compile-time error if it's Err

view this post on Zulip Aurélien Geron (Oct 03 2026 at 22:59):

I created issue #12044

view this post on Zulip Aurélien Geron (Oct 03 2026 at 23:08):

I also updated the example to mention the fact that from_interpolation will soon require returning a Try, just like from_quote and from_numeral, and the compiler will unwrap Ok and reject Err.


Last updated: Oct 15 2026 at 17:56 UTC