forked from metaverse/kernel-dev
放弃使用自定义的format宏
This commit is contained in:
parent
0542277e31
commit
da4c7807b3
|
@ -1,8 +1,6 @@
|
|||
use core::{cmp::Ordering, ops::Sub, time::Duration};
|
||||
|
||||
use alloc::string::ToString;
|
||||
|
||||
use crate::format;
|
||||
use alloc::{format, string::ToString};
|
||||
|
||||
extern "C" {
|
||||
fn system_time_get() -> usize;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
pub mod format;
|
Loading…
Reference in New Issue