Unsure about a few std macros

I have a few questions:

  1. Macros like column, file and line mention

The returned column is not necessarily the line of the column! invocation itself, but rather the first macro invocation leading up to the invocation of the column! macro.

Is this about situation where macro expands to code containing column/file/line macro?

  1. format_args

format_args!, unlike its derived macros, avoids heap allocations.

Is it because it doesn't create string? I guess "derived macros" are the ones that do.

  1. is_x86_feature_detected

This does not resolve at compile time unless the specified feature is already enabled for the entire crate

Are RUSTFLAGS the way it (resolving at compile time) can be achieved?

  1. write

Note: This macro can be used in no_std setups as well. In a no_std setup you are responsible for the implementation details of the components.

What does that exactly mean? There IS core::fmt::Write, so I don't have to implement it by myself. Is formatting as a process any different in no_std?

2 Likes
  1. Yes
  2. Yes
  3. Yes, I think the key takeaway from this is that if you enable cpu feature x at compile time with RUSTFLAGS -C target-feature=+x, then any is_x86_feature_detected("x") will resolve to true at compile time (and get optimized out).
  4. core::fmt::Write is a trait. There is an implementation for String but String requires alloc. If alloc is unavailable then you will need to provide your own implementation of Write (or get one from a 3rd party crate).
6 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.