放弃使用自定义的format宏

This commit is contained in:
pointer-to-bios 2024-02-05 21:57:33 +08:00
parent 0542277e31
commit da4c7807b3
3 changed files with 1 additions and 42 deletions

View File

@ -1,8 +1,6 @@
use core::{cmp::Ordering, ops::Sub, time::Duration}; use core::{cmp::Ordering, ops::Sub, time::Duration};
use alloc::string::ToString; use alloc::{format, string::ToString};
use crate::format;
extern "C" { extern "C" {
fn system_time_get() -> usize; fn system_time_get() -> usize;

View File

@ -1,38 +0,0 @@
use alloc::string::{String, ToString};
#[macro_export]
macro_rules! format {
( $s : expr, $( $e : expr ),* ) => {{
use crate::libk::string::format::Format;
let mut res = $s.to_string();
$(
res.format($e);
)*
res
}};
() => {};
}
pub trait Format<T: ToString> {
fn format(&mut self, f: T);
}
impl<T: ToString> Format<T> for String {
fn format(&mut self, f: T) {
let mut res = String::new();
let mut formatting = false;
for c in self.chars().into_iter() {
if c == '{' {
formatting = true;
res += &f.to_string();
} else if c == '}' {
formatting = false;
}
if !formatting {
res.push(c);
}
}
self.clear();
self.push_str(&res);
}
}

View File

@ -1 +0,0 @@
pub mod format;