Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a little more infrastructure for building ConversionErrors #235

Closed
wants to merge 2 commits into from

Conversation

graydon
Copy link
Contributor

@graydon graydon commented Jul 19, 2022

A little promised code from meeting earlier today, sorry for delay @jayz22 !

Comment on lines +238 to +241
if let Err(e) = self.debug_event(DebugEvent::new().msg("type conversion failed")) {
return e;
}
if let Err(e) = self.debug_event(DebugEvent::new().msg(core::any::type_name::<T>()).arg(v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can combine these two debug events.

Can we format a msg to include the typename? The typename should be known at compile time, and this fn is generic and bound to the type at compile time, so it should be possible to compose the type conversion into T failed string at compile time.

(We'd need to use something like the const_format crate.)

If we can't do that for some reason, can we truncate and convert the T typename into a Symbol and include it as an arg?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core::any::type_name returns the typename as a string slice.
I can combine these two events and incorporate any other suggestions you may have.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is to just check in Graydon's changes during today's meeting so that I can pick it up and continue on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat, I hadn't seen const_format. Maybe! I will also be fleshing out support for multiple static strings (host and guest) as args beyond the initial msg, so this is very much a stopgap, not the final version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I couldn't figure out how to do it with one debug_event.
const_format (e.g. concatcp! ) doesn't help here because the inputs must be const.
Is there any way to get the compile-time type names?

Copy link
Member

@leighmcculloch leighmcculloch Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so the core::any::typename is a const fn, but only in nightly behind the const_type_name feature. Doh! rust-lang/rust#63084

@jayz22
Copy link
Contributor

jayz22 commented Jul 20, 2022

Closing this as I've incorporated the changes into my follow-up work.

@jayz22 jayz22 closed this Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants