mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 05:11:09 +00:00
Eliminate todo!()
s
This commit is contained in:
parent
5b01c048af
commit
7d25c1b54d
5 changed files with 15 additions and 15 deletions
|
@ -11,7 +11,7 @@ fn main() -> std::io::Result<()> {
|
||||||
let git_hash_short = String::from_utf8_lossy(&output.stdout);
|
let git_hash_short = String::from_utf8_lossy(&output.stdout);
|
||||||
let now = datetime::now();
|
let now = datetime::now();
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let erg_path = std::env::home_dir().unwrap().join(".erg");
|
let erg_path = std::env::home_dir().unwrap_or_default().join(".erg");
|
||||||
println!("cargo:rustc-env=GIT_HASH_SHORT={git_hash_short}");
|
println!("cargo:rustc-env=GIT_HASH_SHORT={git_hash_short}");
|
||||||
println!("cargo:rustc-env=BUILD_DATE={now}");
|
println!("cargo:rustc-env=BUILD_DATE={now}");
|
||||||
println!("cargo:rustc-env=CARGO_ERG_PATH={}", erg_path.display());
|
println!("cargo:rustc-env=CARGO_ERG_PATH={}", erg_path.display());
|
||||||
|
|
|
@ -269,7 +269,7 @@ macro_rules! fn_name {
|
||||||
fn type_name_of<T>(_: T) -> &'static str {
|
fn type_name_of<T>(_: T) -> &'static str {
|
||||||
std::any::type_name::<T>()
|
std::any::type_name::<T>()
|
||||||
}
|
}
|
||||||
let name = type_name_of(dummy).rsplit("::").nth(1).unwrap();
|
let name = type_name_of(dummy).rsplit("::").nth(1).unwrap_or("?");
|
||||||
&name[..]
|
&name[..]
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -624,9 +624,9 @@ impl std::str::FromStr for PythonVersion {
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let mut iter = s.split('.');
|
let mut iter = s.split('.');
|
||||||
let major = iter.next().unwrap().parse::<u8>().unwrap_or(3);
|
let major = iter.next().and_then(|i| i.parse().ok()).unwrap_or(3);
|
||||||
let minor = iter.next().and_then(|i| i.parse::<u8>().ok());
|
let minor = iter.next().and_then(|i| i.parse().ok());
|
||||||
let micro = iter.next().and_then(|i| i.parse::<u8>().ok());
|
let micro = iter.next().and_then(|i| i.parse().ok());
|
||||||
Ok(Self::new(major, minor, micro))
|
Ok(Self::new(major, minor, micro))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -652,9 +652,9 @@ pub fn get_python_version(py_command: &str) -> PythonVersion {
|
||||||
};
|
};
|
||||||
let s_version = String::from_utf8(out.stdout).unwrap();
|
let s_version = String::from_utf8(out.stdout).unwrap();
|
||||||
let mut iter = s_version.split(' ');
|
let mut iter = s_version.split(' ');
|
||||||
let major = iter.next().unwrap().parse().unwrap();
|
let major = iter.next().and_then(|i| i.parse().ok()).unwrap_or(3);
|
||||||
let minor = iter.next().and_then(|i| i.parse::<u8>().ok());
|
let minor = iter.next().and_then(|i| i.parse().ok());
|
||||||
let micro = iter.next().and_then(|i| i.trim_end().parse::<u8>().ok());
|
let micro = iter.next().and_then(|i| i.trim_end().parse().ok());
|
||||||
PythonVersion {
|
PythonVersion {
|
||||||
major,
|
major,
|
||||||
minor,
|
minor,
|
||||||
|
|
|
@ -40,8 +40,8 @@ pub const fn get_ver_from_magic_num(magic_num: u32) -> PythonVersion {
|
||||||
pub fn get_timestamp_bytes() -> [u8; 4] {
|
pub fn get_timestamp_bytes() -> [u8; 4] {
|
||||||
let secs = SystemTime::now()
|
let secs = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.map(|dur| dur.as_secs() as u32)
|
||||||
.as_secs() as u32;
|
.unwrap_or(0);
|
||||||
secs.to_le_bytes()
|
secs.to_le_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -417,7 +417,7 @@ impl StyledStrings {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
pub fn push_str(&mut self, s: &str) {
|
pub fn push_str(&mut self, s: &str) {
|
||||||
if self.is_same_color(Color::Gray) {
|
if self.color_is(Color::Gray) {
|
||||||
self.texts.last_mut().unwrap().text.push_str(s);
|
self.texts.last_mut().unwrap().text.push_str(s);
|
||||||
} else {
|
} else {
|
||||||
self.texts.push(StyledString::new(s, None, None));
|
self.texts.push(StyledString::new(s, None, None));
|
||||||
|
@ -438,7 +438,7 @@ impl StyledStrings {
|
||||||
/// println!("{}", texts);
|
/// println!("{}", texts);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn push_str_with_color<'a, S: Into<Cow<'a, str>>>(&mut self, s: S, color: Color) {
|
pub fn push_str_with_color<'a, S: Into<Cow<'a, str>>>(&mut self, s: S, color: Color) {
|
||||||
if self.is_same_color(color) {
|
if self.color_is(color) {
|
||||||
let text = s.into();
|
let text = s.into();
|
||||||
self.texts.last_mut().unwrap().text.push_str(&text);
|
self.texts.last_mut().unwrap().text.push_str(&text);
|
||||||
} else {
|
} else {
|
||||||
|
@ -465,7 +465,7 @@ impl StyledStrings {
|
||||||
color: Color,
|
color: Color,
|
||||||
attr: Attribute,
|
attr: Attribute,
|
||||||
) {
|
) {
|
||||||
if self.is_same_color(color) && self.is_same_attribute(attr) {
|
if self.color_is(color) && self.attr_is(attr) {
|
||||||
let text = s.into();
|
let text = s.into();
|
||||||
self.texts.last_mut().unwrap().text.push_str(&text);
|
self.texts.last_mut().unwrap().text.push_str(&text);
|
||||||
} else {
|
} else {
|
||||||
|
@ -482,14 +482,14 @@ impl StyledStrings {
|
||||||
self.texts.iter().all(|s| s.is_empty())
|
self.texts.iter().all(|s| s.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_same_color(&self, color: Color) -> bool {
|
fn color_is(&self, color: Color) -> bool {
|
||||||
if let Some(text) = self.texts.last() {
|
if let Some(text) = self.texts.last() {
|
||||||
return text.color == Some(color);
|
return text.color == Some(color);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_same_attribute(&self, attr: Attribute) -> bool {
|
fn attr_is(&self, attr: Attribute) -> bool {
|
||||||
if let Some(text) = self.texts.last() {
|
if let Some(text) = self.texts.last() {
|
||||||
if let Some(text_attr) = text.attribute {
|
if let Some(text_attr) = text.attribute {
|
||||||
return text_attr == attr;
|
return text_attr == attr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue