Comments (5)
To be exact, it is a common behavior that formatting implementations discard the width and alignment information:
fn main() {
println!("{:>11?}", "a\nb\nc"); // not aligned
println!("{:>11}", format!("{:?}", "a\nb\nc")); // aligned
}
I would argue that this behavior is, while frustrating, justifiable because alignment requires the length of printed string beforehand and this might not be acceptable for many types. (For the case of strftime
, I think there is no efficient and seemingly-correct solution; Formatter::pad
obviously requires the string length.) But it is frustrating, and I agree that this has to be discussed and at least documented.
from time.
If a type does not support alignment, then println!
should fail at compile time IMHO.
Alas, this would not be backwards compatible. So we can only make it give a warning.
from time.
Yes @lifthrasiir is right in that most types do not support the width/alignment of the underlying formatting system, and the best solution to this (as you've found) is to call .to_string()
and then pad that accordingly. This is currently as-intended, however, and the documentation should probably happen in std::fmt
instead of just in this library, so I'm going to close this issue.
from time.
This is currently as-intended, however
Poop. Ok, that was really frustrating. Maybe a warning? A warning would have saved a lot of angst.
the documentation should probably happen in std::fmt instead of just in this library, so I'm going to close this issue.
Where can I submit a PR for that?
from time.
Maybe a warning? A warning would have saved a lot of angst
Unfortunately there's no way for the formatting infrastructure to know whether a type actually looks at the formatting flags or not (as it's all trait-based).
Where can I submit a PR for that?
A PR editing this file should do the trick!
from time.
Related Issues (20)
- fn OffsetDateTime::date_time(self) if private HOT 1
- Optional weekday for rfc2822 HOT 2
- year repr:last_two removed in 0.3.x? HOT 1
- Optional leading zeros and parsing HOT 3
- Implement `FromStr` for `PrimitiveDateTime` and `OffsetDateTime` HOT 1
- `subsec_{milli,micro,nano}seconds` may have over-inclusive documented ranges HOT 1
- Default `impl Deserialize`/`impl Serialize for time::OffsetDateTime` is a footgun HOT 1
- Mark the date_time function from OffsetDateTime as public HOT 1
- Bug with leap second parsing ISO 8601 HOT 6
- Renaming of `FormatItem` is a breaking change HOT 5
- How to use `serde::format_description` with `format_description::well_known` ? HOT 5
- Confusing deprecation message for `time::Instant` HOT 3
- Formatting bug on ISO8601 HOT 6
- Make `format` methods localizable HOT 6
- Error with rust-nightly: type annotations needed for `Box<_>` HOT 7
- Solve "large-dates" ambiguity HOT 1
- parsing: option to [end] to terminate parsing even if there is further input HOT 1
- compile error: time-0.3.29/src/format_description/parse/mod.rs:83:9 "type must be known at this point" HOT 2
- Document status of local-offset support HOT 2
- Provide cached local offset HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from time.