Skip to content

Conversation

@MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Sep 27, 2024

This PR makes it possible to wrap Rust's native string in Object<> while printing will print them correctly. I added a test in DafnyRuntimeRust

This PR might break external code which created Object<> of things that Dafny did not support originally, but I'm not aware of any other external code that was making use of that. Moreover, there is a workaround by creating the appropriate Upcast trait.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

alex-chew
alex-chew previously approved these changes Sep 27, 2024
Copy link
Contributor

@alex-chew alex-chew left a comment

Choose a reason for hiding this comment

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

LGTM. I also suggested a minor optimization.

impl <T: ?Sized + UpcastObject<dyn Any>> DafnyPrint for Object<T> {
fn fmt_print(&self, f: &mut Formatter<'_>, _in_seq: bool) -> std::fmt::Result {
write!(f, "<object>")
let option_string = UpcastObject::<dyn Any>::upcast(self.as_ref()).as_ref().downcast_ref::<String>().cloned();
Copy link
Contributor

Choose a reason for hiding this comment

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

This clone is avoidable:

Suggested change
let option_string = UpcastObject::<dyn Any>::upcast(self.as_ref()).as_ref().downcast_ref::<String>().cloned();
let obj_any = UpcastObject::<dyn Any>::upcast(self.as_ref());
let option_string = obj_any.as_ref().downcast_ref::<String>();

@MikaelMayer MikaelMayer enabled auto-merge (squash) September 27, 2024 21:55
@MikaelMayer MikaelMayer merged commit 38db1b8 into master Sep 27, 2024
22 checks passed
@MikaelMayer MikaelMayer deleted the feat-print-rust-object-string branch September 27, 2024 22:12
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.

2 participants