mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 12:51:10 +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 now = datetime::now();
|
||||
#[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=BUILD_DATE={now}");
|
||||
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 {
|
||||
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[..]
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -624,9 +624,9 @@ impl std::str::FromStr for PythonVersion {
|
|||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut iter = s.split('.');
|
||||
let major = iter.next().unwrap().parse::<u8>().unwrap_or(3);
|
||||
let minor = iter.next().and_then(|i| i.parse::<u8>().ok());
|
||||
let micro = iter.next().and_then(|i| i.parse::<u8>().ok());
|
||||
let major = iter.next().and_then(|i| i.parse().ok()).unwrap_or(3);
|
||||
let minor = iter.next().and_then(|i| i.parse().ok());
|
||||
let micro = iter.next().and_then(|i| i.parse().ok());
|
||||
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 mut iter = s_version.split(' ');
|
||||
let major = iter.next().unwrap().parse().unwrap();
|
||||
let minor = iter.next().and_then(|i| i.parse::<u8>().ok());
|
||||
let micro = iter.next().and_then(|i| i.trim_end().parse::<u8>().ok());
|
||||
let major = iter.next().and_then(|i| i.parse().ok()).unwrap_or(3);
|
||||
let minor = iter.next().and_then(|i| i.parse().ok());
|
||||
let micro = iter.next().and_then(|i| i.trim_end().parse().ok());
|
||||
PythonVersion {
|
||||
major,
|
||||
minor,
|
||||
|
|
|
@ -40,8 +40,8 @@ pub const fn get_ver_from_magic_num(magic_num: u32) -> PythonVersion {
|
|||
pub fn get_timestamp_bytes() -> [u8; 4] {
|
||||
let secs = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as u32;
|
||||
.map(|dur| dur.as_secs() as u32)
|
||||
.unwrap_or(0);
|
||||
secs.to_le_bytes()
|
||||
}
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ impl StyledStrings {
|
|||
///
|
||||
/// ```
|
||||
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);
|
||||
} else {
|
||||
self.texts.push(StyledString::new(s, None, None));
|
||||
|
@ -438,7 +438,7 @@ impl StyledStrings {
|
|||
/// println!("{}", texts);
|
||||
/// ```
|
||||
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();
|
||||
self.texts.last_mut().unwrap().text.push_str(&text);
|
||||
} else {
|
||||
|
@ -465,7 +465,7 @@ impl StyledStrings {
|
|||
color: Color,
|
||||
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();
|
||||
self.texts.last_mut().unwrap().text.push_str(&text);
|
||||
} else {
|
||||
|
@ -482,14 +482,14 @@ impl StyledStrings {
|
|||
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() {
|
||||
return text.color == Some(color);
|
||||
}
|
||||
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_attr) = text.attribute {
|
||||
return text_attr == attr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue