1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-10 04:12:20 +00:00

fix: apply nightly clippy & fmt suggestions (#1922)

This commit is contained in:
David Knaack 2020-11-23 20:38:11 +01:00 committed by GitHub
parent 4b85b40cb0
commit cf297ff25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 23 deletions

View File

@ -349,28 +349,31 @@ impl<'a> StringFormatter<'a> {
impl<'a> VariableHolder<String> for StringFormatter<'a> {
fn get_variables(&self) -> BTreeSet<String> {
BTreeSet::from_iter(self.variables.keys().cloned())
self.variables.keys().cloned().collect()
}
}
impl<'a> StyleVariableHolder<String> for StringFormatter<'a> {
fn get_style_variables(&self) -> BTreeSet<String> {
BTreeSet::from_iter(self.style_variables.keys().cloned())
self.style_variables.keys().cloned().collect()
}
}
fn clone_without_meta<'a>(variables: &VariableMapType<'a>) -> VariableMapType<'a> {
VariableMapType::from_iter(variables.iter().map(|(key, value)| {
let value = match value {
Some(Ok(value)) => match value {
VariableValue::Meta(_) => None,
other => Some(Ok(other.clone())),
},
Some(Err(e)) => Some(Err(e.clone())),
None => None,
};
(key.clone(), value)
}))
variables
.iter()
.map(|(key, value)| {
let value = match value {
Some(Ok(value)) => match value {
VariableValue::Meta(_) => None,
other => Some(Ok(other.clone())),
},
Some(Err(e)) => Some(Err(e.clone())),
None => None,
};
(key.clone(), value)
})
.collect()
}
#[cfg(test)]

View File

@ -250,7 +250,7 @@ fn get_pinned_sdk_version(json: &str) -> Option<Version> {
}
}
fn get_local_dotnet_files<'a>(context: &'a Context) -> Result<Vec<DotNetFile>, std::io::Error> {
fn get_local_dotnet_files(context: &Context) -> Result<Vec<DotNetFile>, std::io::Error> {
Ok(context
.dir_contents()?
.files()

View File

@ -31,7 +31,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
//rustc doesn't let you do an "if" and an "if let" in the same if statement
// if this changes in the future this can become a lot cleaner
let host = if config.trim_at != "" {
let host = if !config.trim_at.is_empty() {
if let Some(index) = host.find(config.trim_at) {
host.split_at(index).0
} else {

View File

@ -62,7 +62,7 @@ fn parse_nim_version(version_cmd_output: &str) -> Option<&str> {
// First line has the version
.next()?
.split(' ')
.find(|&s| s.chars().all(|c| c >= '0' && c <= '9' || c == '.'))
.find(|&s| s.chars().all(|c| ('0'..='9').contains(&c) || c == '.'))
}
#[cfg(test)]

View File

@ -74,11 +74,10 @@ fn create_offset_time_string(
time_format: &str,
) -> Result<String, &'static str> {
// Using floats to allow 30/45 minute offsets: https://www.timeanddate.com/time/time-zones-interesting.html
let utc_time_offset_in_hours = match utc_time_offset_str.parse::<f32>() {
Ok(parsed_value) => parsed_value,
let utc_time_offset_in_hours = utc_time_offset_str.parse::<f32>().unwrap_or(
// Passing out of range value to force falling back to "local"
Err(_) => 25_f32,
};
25_f32,
);
if utc_time_offset_in_hours < 24_f32 && utc_time_offset_in_hours > -24_f32 {
let utc_offset_in_seconds: i32 = (utc_time_offset_in_hours * 3600_f32) as i32;
let timezone_offset = FixedOffset::east(utc_offset_in_seconds);

View File

@ -10,7 +10,7 @@ pub fn truncate(dir_string: String, length: usize) -> String {
let mut components = dir_string.split('/').collect::<Vec<&str>>();
// If the first element is "" then there was a leading "/" and we should remove it so we can check the actual count of components
if components[0] == "" {
if components[0].is_empty() {
components.remove(0);
}

View File

@ -101,7 +101,7 @@ pub fn is_write_allowed(folder_path: &Path) -> std::result::Result<bool, &'stati
let mut priv_size = mem::size_of::<PRIVILEGE_SET>() as DWORD;
let mut granted_access: DWORD = 0;
let mut access_rights: DWORD = FILE_GENERIC_WRITE;
let mut result: BOOL = 0 as BOOL;
let mut result: BOOL = 0;
unsafe { securitybaseapi::MapGenericMask(&mut access_rights, &mut mapping) };
let rc = unsafe {
securitybaseapi::AccessCheck(

View File

@ -197,7 +197,7 @@ pub fn explain(args: ArgMatches) {
}
if escaping {
print!("{}", g);
escaping = !("a" <= g && "z" >= g || "A" <= g && "Z" >= g);
escaping = !(("a"..="z").contains(&g) || ("A"..="Z").contains(&g));
continue;
}