You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you write log!("{x}"), it outputs {x} literally instead of the value of variable x because log! is implemented differently if it has only 1 expression:
log!("{x}",) (with a trailing comma) bypasses this, but I think it would be nice to maintain 100% compatibility with std::fmt.
If a string allocation makes a significant difference for some contract, is there a reason why they can't just use env::log_str directly? This call will also explicitly mark that this log outputs a lot of data and should not be changed to something that allocates, to avoid situations when at some point you add one {} to the log, and gas usage skyrockets for an unknown reason.
The text was updated successfully, but these errors were encountered:
@Sliman4 The macro was implemented before string interpolation became a thing in Rust (stable). I agree with your reasoning. Would you like to prepare a PR?
When you write
log!("{x}")
, it outputs{x}
literally instead of the value of variablex
becauselog!
is implemented differently if it has only 1 expression:near-sdk-rs/near-sdk/src/utils/mod.rs
Lines 36 to 43 in 8a908c3
log!("{x}",)
(with a trailing comma) bypasses this, but I think it would be nice to maintain 100% compatibility withstd::fmt
.If a string allocation makes a significant difference for some contract, is there a reason why they can't just use
env::log_str
directly? This call will also explicitly mark that this log outputs a lot of data and should not be changed to something that allocates, to avoid situations when at some point you add one{}
to the log, and gas usage skyrockets for an unknown reason.The text was updated successfully, but these errors were encountered: