Add format and cformat modules from RustPython#24
Add format and cformat modules from RustPython#24youknowone merged 3 commits intoRustPython:mainfrom
format and cformat modules from RustPython#24Conversation
literal/src/format.rs
Outdated
| pub trait CharLen { | ||
| /// Returns the number of characters in the text | ||
| fn char_len(&self) -> usize; | ||
| } | ||
|
|
||
| struct AsciiStr<'a> { | ||
| inner: &'a str, | ||
| } | ||
|
|
||
| impl<'a> AsciiStr<'a> { | ||
| fn new(inner: &'a str) -> Self { | ||
| Self { inner } | ||
| } | ||
| } | ||
|
|
||
| impl CharLen for AsciiStr<'_> { | ||
| fn char_len(&self) -> usize { | ||
| self.inner.len() | ||
| } | ||
| } | ||
|
|
||
| impl Deref for AsciiStr<'_> { | ||
| type Target = str; | ||
| fn deref(&self) -> &Self::Target { | ||
| self.inner | ||
| } | ||
| } |
b26bb1e to
d967b34
Compare
d967b34 to
263f96f
Compare
|
I feel a bit awkward to put format functions to parser directory. But that will be fine if it helps to maintaining Ruff in practice. |
I understand. Would it help if we move the logic into a new |
|
Either way will be good to me. |
|
I added a new crate and updated the repository URLs. |
|
Thank you! |
* Add `format` and `cformat` modules from `RustPython` * Introduce `rustpython-format` crate * Remove unused dependencies
This PR moves the
formatandcformatmodules fromRustPythoninto the newformatcrate. I'm not sure if this is the right crate to add. Please let me know if I should move it to another crate and/or add it behind a feature flag.The
formatimplementation has an optimized path forBorrowedStr. I kept that path by introducing a newCharLentrait thatBorrowedStrcan implement inRustPython.The goal of this is that
formatandcformatare the last two modules fromRustPythonthat ruff depends on. Moving them into this repository would allow us to cut that dependency.