Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf57a820 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: Remove redundant `String::from(format!(...))`

format!() already returns String.

Bug: 342337056
Tag: #floss
Test: mmm packages/modules/Bluetooth
Flag: EXEMPT, Floss-only changes
Change-Id: I16a15cdfe2832379da4c494b63426bf8aa9e807f
parent 545cc3b0
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -206,13 +206,13 @@ fn read_propmap_value<T: 'static + DirectDBus>(
) -> Result<T, Box<dyn std::error::Error>> {
    let output = propmap
        .get(key)
        .ok_or(Box::new(DBusArgError::new(String::from(format!("Key {} does not exist", key,)))))?;
        .ok_or(Box::new(DBusArgError::new(format!("Key {} does not exist", key,))))?;
    let output = <T as RefArgToRust>::ref_arg_to_rust(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(String::from(format!(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(format!(
            "Unable to convert propmap[\"{}\"] to {}",
            key,
            stringify!(T),
        )))))?,
        ))))?,
        String::from(stringify!(T)),
    )?;
    Ok(output)
@@ -227,13 +227,13 @@ where
{
    let output = propmap
        .get(key)
        .ok_or(Box::new(DBusArgError::new(String::from(format!("Key {} does not exist", key,)))))?;
        .ok_or(Box::new(DBusArgError::new(format!("Key {} does not exist", key,))))?;
    let output = <<T as DBusArg>::DBusType as RefArgToRust>::ref_arg_to_rust(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(String::from(format!(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(format!(
            "Unable to convert propmap[\"{}\"] to {}",
            key,
            stringify!(T),
        )))))?,
        ))))?,
        format!("{}", stringify!(T)),
    )?;
    let output = T::from_dbus(output, None, None, None)?;
@@ -490,18 +490,18 @@ impl DBusArg for ScanFilterCondition {
        let variant = match data.get("patterns") {
            Some(variant) => variant,
            None => {
                return Err(Box::new(DBusArgError::new(String::from(format!(
                return Err(Box::new(DBusArgError::new(String::from(
                    "ScanFilterCondition does not contain any enum variant",
                )))));
                ))));
            }
        };

        match variant.arg_type() {
            dbus::arg::ArgType::Variant => {}
            _ => {
                return Err(Box::new(DBusArgError::new(String::from(format!(
                return Err(Box::new(DBusArgError::new(String::from(
                    "ScanFilterCondition::Patterns must be a variant",
                )))));
                ))));
            }
        };

+1 −1
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ impl ClientContext {
        // Trigger callback registration in the foreground
        let fg = self.fg.clone();
        tokio::spawn(async move {
            let adapter = String::from(format!("adapter{}", idx));
            let adapter = format!("adapter{}", idx);
            // Floss won't export the interface until it is ready to be used.
            // Wait 1 second before registering the callbacks.
            sleep(Duration::from_millis(1000)).await;
+20 −20
Original line number Diff line number Diff line
@@ -634,10 +634,10 @@ pub fn dbus_propmap(attr: TokenStream, item: TokenStream) -> TokenStream {
            match #field_ident.arg_type() {
                dbus::arg::ArgType::Variant => {}
                _ => {
                    return Err(Box::new(DBusArgError::new(String::from(format!(
                    return Err(Box::new(DBusArgError::new(format!(
                        "{}.{} must be a variant",
                        #struct_str, #field_str
                    )))));
                    ))));
                }
            };
            let #field_ident = <<#field_type as DBusArg>::DBusType as RefArgToRust>::ref_arg_to_rust(
@@ -659,10 +659,10 @@ pub fn dbus_propmap(attr: TokenStream, item: TokenStream) -> TokenStream {
            let #field_ident = match data__.get(#field_str) {
                Some(data) => data,
                None => {
                    return Err(Box::new(DBusArgError::new(String::from(format!(
                    return Err(Box::new(DBusArgError::new(format!(
                        "{}.{} is required",
                        #struct_str, #field_str
                    )))));
                    ))));
                }
            };
            #make_field
@@ -992,7 +992,7 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
            }

            fn log(_data: &Box<dyn #trait_ + Send>) -> String {
                String::from(format!("Box<dyn>"))
                format!("Box<dyn>")
            }
        }
    };
@@ -1071,12 +1071,12 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            ) -> Result<Self::RustType, Box<dyn Error>> {
                let any = arg.as_any();
                if !any.is::<<Self as DBusArg>::DBusType>() {
                    return Err(Box::new(DBusArgError::new(String::from(format!(
                    return Err(Box::new(DBusArgError::new(format!(
                        "{} type does not match: expected {}, found {}",
                        name,
                        std::any::type_name::<<Self as DBusArg>::DBusType>(),
                        arg.arg_type().as_str(),
                    )))));
                    ))));
                }
                let arg = (*any.downcast_ref::<<Self as DBusArg>::DBusType>().unwrap()).clone();
                return Ok(arg);
@@ -1092,16 +1092,16 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            ) -> Result<Self::RustType, Box<dyn Error>> {
                let any = arg.as_any();
                if !any.is::<<Self as DBusArg>::DBusType>() {
                    return Err(Box::new(DBusArgError::new(String::from(format!(
                    return Err(Box::new(DBusArgError::new(format!(
                        "{} type does not match: expected {}, found {}",
                        name,
                        std::any::type_name::<<Self as DBusArg>::DBusType>(),
                        arg.arg_type().as_str(),
                    )))));
                    ))));
                }
                let arg = match (*any.downcast_ref::<<Self as DBusArg>::DBusType>().unwrap()).try_clone() {
                    Ok(foo) => foo,
                    Err(_) => return Err(Box::new(DBusArgError::new(String::from(format!("{} cannot clone file.", name))))),
                    Err(_) => return Err(Box::new(DBusArgError::new(format!("{} cannot clone file.", name)))),
                };

                return Ok(arg);
@@ -1117,10 +1117,10 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
                let mut map: dbus::arg::PropMap = std::collections::HashMap::new();
                let mut iter = match arg.as_iter() {
                    None => {
                        return Err(Box::new(DBusArgError::new(String::from(format!(
                        return Err(Box::new(DBusArgError::new(format!(
                            "{} is not iterable",
                            name,
                        )))))
                        ))))
                    }
                    Some(item) => item,
                };
@@ -1132,10 +1132,10 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
                    let v = dbus::arg::Variant(
                        val_clone
                            .as_static_inner(0)
                            .ok_or(Box::new(DBusArgError::new(String::from(format!(
                            .ok_or(Box::new(DBusArgError::new(format!(
                                "{}.{} is not a variant",
                                name, k
                            )))))?
                            ))))?
                            .box_clone(),
                    );
                    map.insert(k, v);
@@ -1258,7 +1258,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            }

            fn log(data: &T) -> String {
                String::from(format!("{}", data))
                format!("{}", data)
            }
        }

@@ -1282,7 +1282,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            }

            fn log(data: &std::fs::File) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }

@@ -1318,7 +1318,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            }

            fn log(data: &Vec<T>) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }

@@ -1352,7 +1352,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
                match prop_value.arg_type() {
                    dbus::arg::ArgType::Variant => (),
                    _ => {
                        return Err(Box::new(DBusArgError::new(String::from(format!("{} must be a variant", OPTION_KEY)))));
                        return Err(Box::new(DBusArgError::new(format!("{} must be a variant", OPTION_KEY))));
                    }
                };

@@ -1384,7 +1384,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            }

            fn log(data: &Option<T>) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }

@@ -1440,7 +1440,7 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
            }

            fn log(data: &std::collections::HashMap<K, V>) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }
    };
+8 −8
Original line number Diff line number Diff line
@@ -266,11 +266,11 @@ macro_rules! impl_dbus_arg_enum {
            ) -> Result<$enum_type, Box<dyn std::error::Error>> {
                match <$enum_type>::from_u32(data) {
                    Some(x) => Ok(x),
                    None => Err(Box::new(DBusArgError::new(String::from(format!(
                    None => Err(Box::new(DBusArgError::new(format!(
                        "error converting {} to {}",
                        data,
                        stringify!($enum_type)
                    ))))),
                    )))),
                }
            }

@@ -279,7 +279,7 @@ macro_rules! impl_dbus_arg_enum {
            }

            fn log(data: &$enum_type) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }
    };
@@ -300,28 +300,28 @@ macro_rules! impl_dbus_arg_from_into {
                >,
            ) -> Result<$rust_type, Box<dyn std::error::Error>> {
                match <$rust_type>::try_from(data.clone()) {
                    Err(e) => Err(Box::new(DBusArgError::new(String::from(format!(
                    Err(e) => Err(Box::new(DBusArgError::new(format!(
                        "error converting {:?} to {:?}",
                        data,
                        stringify!($rust_type),
                    ))))),
                    )))),
                    Ok(result) => Ok(result),
                }
            }

            fn to_dbus(data: $rust_type) -> Result<$dbus_type, Box<dyn std::error::Error>> {
                match data.clone().try_into() {
                    Err(e) => Err(Box::new(DBusArgError::new(String::from(format!(
                    Err(e) => Err(Box::new(DBusArgError::new(format!(
                        "error converting {:?} to {:?}",
                        data,
                        stringify!($dbus_type)
                    ))))),
                    )))),
                    Ok(result) => Ok(result),
                }
            }

            fn log(data: &$rust_type) -> String {
                String::from(format!("{:?}", data))
                format!("{:?}", data)
            }
        }
    };
+7 −7
Original line number Diff line number Diff line
@@ -294,13 +294,13 @@ fn read_propmap_value<T: 'static + DirectDBus>(
) -> Result<T, Box<dyn std::error::Error>> {
    let output = propmap
        .get(key)
        .ok_or(Box::new(DBusArgError::new(String::from(format!("Key {} does not exist", key,)))))?;
        .ok_or(Box::new(DBusArgError::new(format!("Key {} does not exist", key,))))?;
    let output = <T as RefArgToRust>::ref_arg_to_rust(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(String::from(format!(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(format!(
            "Unable to convert propmap[\"{}\"] to {}",
            key,
            stringify!(T),
        )))))?,
        ))))?,
        String::from(stringify!(T)),
    )?;
    Ok(output)
@@ -315,13 +315,13 @@ where
{
    let output = propmap
        .get(key)
        .ok_or(Box::new(DBusArgError::new(String::from(format!("Key {} does not exist", key,)))))?;
        .ok_or(Box::new(DBusArgError::new(format!("Key {} does not exist", key,))))?;
    let output = <<T as DBusArg>::DBusType as RefArgToRust>::ref_arg_to_rust(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(String::from(format!(
        output.as_static_inner(0).ok_or(Box::new(DBusArgError::new(format!(
            "Unable to convert propmap[\"{}\"] to {}",
            key,
            stringify!(T),
        )))))?,
        ))))?,
        format!("{}", stringify!(T)),
    )?;
    let output = T::from_dbus(output, None, None, None)?;
@@ -433,7 +433,7 @@ impl DBusArg for BtSdpRecord {
    }

    fn log(record: &BtSdpRecord) -> String {
        String::from(format!("{:?}", record))
        format!("{:?}", record)
    }
}

Loading