Tracking Issue for `FormattingOptions`
Open
@EliasHolzmann is already working on this.
Since Nov 21, 2023.
C-tracking-issue
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Feature gate: #![feature(formatting_options)]
This is a tracking issue for fmt::FormattingOptions.
FormattingOptions can be used to construct custom Formatters at runtime.
Public API
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FormattingOptions { … }
enum Sign {
Plus,
Minus
}
impl FormattingOptions {
pub fn new() -> Self;
pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self;
pub fn zero_pad(&mut self, zero_pad: bool) -> &mut Self;
pub fn alternate(&mut self, alternate: bool) -> &mut Self;
pub fn fill(&mut self, fill: Option<char>) -> &mut Self;
pub fn alignment(&mut self, alignment: Option<Alignment>) -> &mut Self;
pub fn width(&mut self, width: Option<usize>) -> &mut Self;
pub fn precision(&mut self, precision: Option<usize>) -> &mut Self;
pub fn get_sign(&self) -> Option<Sign>;
pub fn get_zero_pad(&self) -> bool;
pub fn get_alternate(&self) -> bool;
pub fn get_fill(&self) -> Option<char>;
pub fn get_alignment(&self) -> Option<Alignment>;
pub fn get_width(&self) -> Option<usize>;
pub fn get_precision(&self) -> Option<usize>;
pub fn create_formatter<'a>(self, write: &'a mut (dyn Write + 'a)) -> Formatter<'a>;
}
impl<'a> Formatter<'a> {
pub fn new(write: &'a mut (dyn Write + 'a), options: FormattingOptions) -> Self;
pub fn with_options(&mut self, options: FormattingOptions) -> Self;
pub fn sign(&self) -> Option<Sign>;
pub fn options(&self) -> FormattingOptions;
}
Steps / History
- API change proposal (ACP)^1: https://github.com/rust-lang/libs-team/issues/286
- Implementation: #118159
- Final comment period (FCP)^2
- Stabilization PR
Unresolved Questions
- Should this expose the "debug as hex" flags? (
{:x?}and{:X?})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.