diff --git a/Cargo.lock b/Cargo.lock index af5c054d..9fa74adb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1260,9 +1260,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "eject" @@ -2851,9 +2851,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "jobserver" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f08474e32172238f2827bd160c67871cdb2801430f65c3979184dc362e3ca118" +checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" dependencies = [ "libc", ] @@ -2958,7 +2958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -2969,9 +2969,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libnghttp2-sys" -version = "0.1.9+1.58.0" +version = "0.1.10+1.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b57e858af2798e167e709b9d969325b6d8e9d50232fcbc494d7d54f976854a64" +checksum = "959c25552127d2e1fa72f0e52548ec04fc386e827ba71a7bd01db46a447dc135" dependencies = [ "cc", "libc", @@ -3779,7 +3779,7 @@ dependencies = [ [[package]] name = "playdate-bindgen" -version = "0.1.7" +version = "0.1.8" dependencies = [ "bindgen", "clap", @@ -3799,14 +3799,14 @@ dependencies = [ [[package]] name = "playdate-bindgen-cfg" -version = "0.1.3" +version = "0.1.4" dependencies = [ "clap", ] [[package]] name = "playdate-build" -version = "0.2.4" +version = "0.2.5" dependencies = [ "crate-metadata", "dirs", @@ -3823,7 +3823,7 @@ dependencies = [ [[package]] name = "playdate-build-utils" -version = "0.3.0" +version = "0.3.1" dependencies = [ "dirs", "log", @@ -3849,7 +3849,7 @@ dependencies = [ [[package]] name = "playdate-device" -version = "0.2.3" +version = "0.2.4" dependencies = [ "async-std", "clap", @@ -3874,7 +3874,7 @@ dependencies = [ "tracing", "udev", "usb-ids", - "windows 0.54.0", + "windows 0.56.0", ] [[package]] @@ -3923,7 +3923,7 @@ dependencies = [ [[package]] name = "playdate-simulator-utils" -version = "0.1.3" +version = "0.1.4" dependencies = [ "async-std", "log", @@ -3971,7 +3971,7 @@ dependencies = [ [[package]] name = "playdate-tool" -version = "0.3.0" +version = "0.3.1" dependencies = [ "clap", "console-subscriber", @@ -5550,41 +5550,65 @@ dependencies = [ [[package]] name = "windows" -version = "0.54.0" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49" +checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132" dependencies = [ "windows-core", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] name = "windows-core" -version = "0.54.0" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65" +checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6" dependencies = [ + "windows-implement", + "windows-interface", "windows-result", - "windows-targets 0.52.4", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "windows-interface" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", ] [[package]] name = "windows-registry" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e885d2dff8cad07e7451b78eac1ff62f958825c4598d6ddf87e7d2661980c1c" +checksum = "f721bc2e55efb506a1a395a545cb76c2481fb023d33b51f0050e7888716281cf" dependencies = [ "windows-result", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] name = "windows-result" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64" +checksum = "749f0da9cc72d82e600d8d2e44cadd0b9eedb9038f71a1c58556ac1c5791813b" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -5602,7 +5626,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -5622,17 +5646,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -5643,9 +5668,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -5661,9 +5686,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -5679,9 +5704,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -5697,9 +5728,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -5715,9 +5746,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -5727,9 +5758,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -5745,9 +5776,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" diff --git a/support/bindgen-cfg/Cargo.toml b/support/bindgen-cfg/Cargo.toml index 38a144e7..3bcd70c9 100644 --- a/support/bindgen-cfg/Cargo.toml +++ b/support/bindgen-cfg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-bindgen-cfg" -version = "0.1.3" +version = "0.1.4" readme = "README.md" description = "Minimal configuration for playdate-bindgen." keywords = ["playdate", "bindings", "ffi", "code-generation"] diff --git a/support/bindgen-cfg/src/lib.rs b/support/bindgen-cfg/src/lib.rs index 3df513cc..8f10dd90 100644 --- a/support/bindgen-cfg/src/lib.rs +++ b/support/bindgen-cfg/src/lib.rs @@ -48,7 +48,7 @@ pub struct Runner; impl Runner { /// Returns path and version of the `pdbindgen` executable if found. - pub fn find_tool<'t>(cfg: &'t Cfg) -> Option<(&'t Path, String)> { + pub fn find_tool(cfg: &Cfg) -> Option<(&Path, String)> { Command::new(&cfg.bin).arg("-V") .stdout(Stdio::piped()) .stderr(Stdio::inherit()) @@ -103,11 +103,10 @@ impl Runner { }); // Easiest way to get existing SDK version: - let sdk_version = path.map(|path| { + let sdk_version = path.and_then(|path| { std::fs::read_to_string(path.join("VERSION.txt")).ok() .map(|s| s.trim().to_string()) }) - .flatten() .filter(|s| !s.is_empty()); // Alternative way is to execute the tool: @@ -385,11 +384,10 @@ impl Target { if var("TARGET")? == "thumbv7em-none-eabihf" { Ok(Self::Playdate) } else { - use core::mem::size_of; use core::ffi::c_int; let ptr = var("CARGO_CFG_TARGET_POINTER_WIDTH")?; Ok(Self::Other { ptr, - c_int: size_of::() * 8 }) + c_int: c_int::BITS as usize }) } } } diff --git a/support/bindgen/Cargo.toml b/support/bindgen/Cargo.toml index 3eb80fb5..e6514d33 100644 --- a/support/bindgen/Cargo.toml +++ b/support/bindgen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-bindgen" -version = "0.1.7" +version = "0.1.8" readme = "README.md" description = "Bindgen configuration for Playdate API and utils." keywords = ["playdate", "bindings", "ffi", "code-generation"] diff --git a/support/bindgen/src/gen/docs/gen.rs b/support/bindgen/src/gen/docs/gen.rs index 93bace70..907c59c9 100644 --- a/support/bindgen/src/gen/docs/gen.rs +++ b/support/bindgen/src/gen/docs/gen.rs @@ -11,8 +11,8 @@ use super::DocsMap; pub fn engage(bindings: &mut syn::File, root: &str, docs: &DocsMap) -> Result<()> { let items = Cell::from_mut(&mut bindings.items[..]); let items_cells = items.as_slice_of_cells(); - if let Some(root) = find_struct(items_cells, &root) { - walk_struct(items_cells, None, root, &docs); + if let Some(root) = find_struct(items_cells, root) { + walk_struct(items_cells, None, root, docs); } Ok(()) @@ -20,19 +20,19 @@ pub fn engage(bindings: &mut syn::File, root: &str, docs: &DocsMap) -> Result<() fn find_struct<'t>(items: &'t [Cell], name: &str) -> Option<&'t mut ItemStruct> { - items.into_iter().find_map(|item| { - match unsafe { item.as_ptr().as_mut() }.expect("cell is null, impossible") { - syn::Item::Struct(entry) if entry.ident.to_string() == name => Some(entry), - _ => None, - } - }) + items.iter().find_map(|item| { + match unsafe { item.as_ptr().as_mut() }.expect("cell is null, impossible") { + syn::Item::Struct(entry) if entry.ident == name => Some(entry), + _ => None, + } + }) } -fn walk_struct<'t>(items: &'t [Cell], - this: Option<&str>, - structure: &mut ItemStruct, - docs: &HashMap) { +fn walk_struct(items: &[Cell], + this: Option<&str>, + structure: &mut ItemStruct, + docs: &HashMap) { let prefix = this.map(|s| format!("{s}.")).unwrap_or("".to_owned()); for field in structure.fields.iter_mut() { let field_name = field.ident.as_ref().expect("field name"); @@ -42,9 +42,9 @@ fn walk_struct<'t>(items: &'t [Cell], match entry.elem.as_mut() { syn::Type::Path(path) => { if let Some(ident) = path.path.get_ident() { - if let Some(mut ty) = find_struct(items, &ident.to_string()) { + if let Some(ty) = find_struct(items, &ident.to_string()) { let key = format!("{prefix}{field_name}"); - walk_struct(items, Some(&key), &mut ty, docs); + walk_struct(items, Some(&key), ty, docs); } } }, @@ -55,24 +55,22 @@ fn walk_struct<'t>(items: &'t [Cell], syn::Type::Path(path) => { if let Some(ident) = path.path.get_ident() { unimplemented!("unexpected struct: '{}'", quote::quote!(#ident)) - } else { - if let Some(ty) = extract_type_from_option(&field.ty) { - match ty { - Type::BareFn(_) => { - let key = format!("{prefix}{field_name}"); - if let Some(doc) = docs.get(&key) { - let attr: syn::Attribute = syn::parse_quote! { #[doc = #doc] }; - field.attrs.push(attr); - } else { - #[cfg(feature = "log")] - println!("cargo:warning=Doc not found for '{key}'"); - } - }, - _ => unimplemented!("unexpected ty: '{}'", quote::quote!(#ty)), - } - } else { - unimplemented!("unexpected ty: '{}'", quote::quote!(#&path)) + } else if let Some(ty) = extract_type_from_option(&field.ty) { + match ty { + Type::BareFn(_) => { + let key = format!("{prefix}{field_name}"); + if let Some(doc) = docs.get(&key) { + let attr: syn::Attribute = syn::parse_quote! { #[doc = #doc] }; + field.attrs.push(attr); + } else { + #[cfg(feature = "log")] + println!("cargo:warning=Doc not found for '{key}'"); + } + }, + _ => unimplemented!("unexpected ty: '{}'", quote::quote!(#ty)), } + } else { + unimplemented!("unexpected ty: '{}'", quote::quote!(#&path)) } }, @@ -100,14 +98,11 @@ fn extract_type_from_option(ty: &syn::Type) -> Option<&syn::Type> { } fn extract_option_segment(path: &Path) -> Option<&PathSegment> { - let idents_of_path = path.segments - .iter() - .into_iter() - .fold(String::new(), |mut acc, v| { - acc.push_str(&v.ident.to_string()); - acc.push('|'); - acc - }); + let idents_of_path = path.segments.iter().fold(String::new(), |mut acc, v| { + acc.push_str(&v.ident.to_string()); + acc.push('|'); + acc + }); vec!["Option|", "std|option|Option|", "core|option|Option|"].into_iter() .find(|s| &idents_of_path == *s) .and_then(|_| path.segments.last()) diff --git a/support/bindgen/src/gen/docs/parser.rs b/support/bindgen/src/gen/docs/parser.rs index 8bcefce2..cf20bb2d 100644 --- a/support/bindgen/src/gen/docs/parser.rs +++ b/support/bindgen/src/gen/docs/parser.rs @@ -65,16 +65,12 @@ fn walk(handle: &Handle, results: &mut DocsMap) { let attrs = attrs.borrow(); let attr = attrs.iter() .find(|attr| attr.name.local == *"id" && attr.value.starts_with("f-")); - if let Some(attr) = attr { - Some( - attr.value - .strip_prefix("f-") - .expect("prefix 'f-' must be there") - .to_string(), - ) - } else { - None - } + attr.map(|attr| { + attr.value + .strip_prefix("f-") + .expect("prefix 'f-' must be there") + .to_string() + }) } else { None }; @@ -112,7 +108,7 @@ fn walk(handle: &Handle, results: &mut DocsMap) { attrs: attrs.clone(), template_contents: template_contents.clone(), mathml_annotation_xml_integration_point: - mathml_annotation_xml_integration_point.clone() }.into() + *mathml_annotation_xml_integration_point }.into() }, _ => None, } @@ -151,8 +147,8 @@ fn walk(handle: &Handle, results: &mut DocsMap) { struct PreAsIsTagFactory; impl TagHandlerFactory for PreAsIsTagFactory { fn instantiate(&self) -> Box { - return Box::new(CodeHandler { lang: "cpp", - ..Default::default() }); + Box::new(CodeHandler { lang: "cpp", + ..Default::default() }) } } // TODO: diff --git a/support/bindgen/src/gen/mod.rs b/support/bindgen/src/gen/mod.rs index de37cdca..7e9542c7 100644 --- a/support/bindgen/src/gen/mod.rs +++ b/support/bindgen/src/gen/mod.rs @@ -25,7 +25,7 @@ pub fn engage(source: &bindgen::Bindings, #[cfg(feature = "documentation")] let docset = if features.documentation { let docset_new = docs::parser::parse(sdk)?; - docs::gen::engage(&mut bindings, &root_struct_name, &docset_new)?; + docs::gen::engage(&mut bindings, root_struct_name, &docset_new)?; Some(docset_new) } else { None diff --git a/support/bindgen/src/lib.rs b/support/bindgen/src/lib.rs index 0b28e8e3..0419db6b 100644 --- a/support/bindgen/src/lib.rs +++ b/support/bindgen/src/lib.rs @@ -98,7 +98,7 @@ impl Generator { let bindings = self.builder.generate()?; #[cfg(not(feature = "extra-codegen"))] - return Ok(bindings).map(Bindings::Bindgen); + return Ok(Bindings::Bindgen(bindings)); #[cfg(feature = "extra-codegen")] gen::engage(&bindings, &self.features, &self.sdk, None).map(Bindings::Engaged) @@ -116,7 +116,7 @@ fn create_generator(cfg: cfg::Cfg) -> Result { let sdk = cfg.sdk .map(|p| Sdk::try_new_exact(p).or_else(|_| Sdk::try_new())) - .unwrap_or_else(|| Sdk::try_new())?; + .unwrap_or_else(Sdk::try_new)?; let version_path = sdk.version_file(); let version_raw = sdk.read_version()?; let version = check_sdk_version(&version_raw)?; @@ -135,13 +135,13 @@ fn create_generator(cfg: cfg::Cfg) -> Result { Gcc::try_from_path(p).and_then(ArmToolchain::try_new_with) .or_else(|_| ArmToolchain::try_new()) }) - .unwrap_or_else(|| ArmToolchain::try_new())?; + .unwrap_or_else(ArmToolchain::try_new)?; let mut builder = create_builder(&cargo_target_triple, &sdk_c_api, &main_header, &cfg.derive); builder = apply_profile(builder, is_debug); builder = apply_target(builder, &cargo_target_triple, &gcc); - let filename = Filename::new(version.to_owned(), &cfg.derive)?; + let filename = Filename::new(version.to_owned(), cfg.derive)?; Ok(Generator { sdk, gcc, @@ -195,6 +195,9 @@ fn create_builder(_target: &str, capi: &Path, header: &Path, derive: &cfg::Deriv .allowlist_var("AUDIO_FRAMES_PER_CYCLE") .allowlist_var("NOTE_C4") + // ignore unused methods that drifting in bindgen result: + .blocklist_function("vaFormatString") + // experimental: .default_macro_constant_type(MacroTypeVariation::Unsigned) .allowlist_var("LCDMakePattern") @@ -425,15 +428,13 @@ pub fn rustfmt<'out>(mut rustfmt_path: Option, match String::from_utf8(output) { Ok(bindings) => { match status.code() { - Some(0) => Ok(bindings.into()), - Some(2) => { - Err(std::io::Error::new(std::io::ErrorKind::Other, "Rustfmt parsing errors.".to_string()).into()) - }, + Some(0) => Ok(bindings), + Some(2) => Err(std::io::Error::new(std::io::ErrorKind::Other, "Rustfmt parsing errors.".to_string())), Some(3) => { println!("cargo:warning=Rustfmt could not format some lines."); - Ok(bindings.into()) + Ok(bindings) }, - _ => Err(std::io::Error::new(std::io::ErrorKind::Other, "Internal rustfmt error".to_string()).into()), + _ => Err(std::io::Error::new(std::io::ErrorKind::Other, "Internal rustfmt error".to_string())), } }, _ => Ok(source), diff --git a/support/build/Cargo.toml b/support/build/Cargo.toml index fc42218a..b252e4a2 100644 --- a/support/build/Cargo.toml +++ b/support/build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-build" -version = "0.2.4" +version = "0.2.5" readme = "README.md" description = "Utils that help to build package for Playdate" keywords = ["playdate", "package", "encoding", "manifest", "assets"] diff --git a/support/build/src/assets/mod.rs b/support/build/src/assets/mod.rs index d76a9a80..1bc70e47 100644 --- a/support/build/src/assets/mod.rs +++ b/support/build/src/assets/mod.rs @@ -48,7 +48,7 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, } let real = path.canonicalize()?; - if !real.starts_with(&target_root) { + if !real.starts_with(target_root) { return Err(IoError::new( IoErrorKind::AlreadyExists, format!("Target points out from target directory: {}", real.display()), @@ -62,35 +62,32 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, let copy_method = |source: &Path, target: &Path, to_inside| -> Result { let into = target_root.join(target); let copied = if source.is_dir() { - ensure_dir_exists(&into, &target_root)?; + ensure_dir_exists(&into, target_root)?; ensure_out_of_root(&into)?; let options = fs_extra::dir::CopyOptions { copy_inside: to_inside, ..def_options }; fs_extra::dir::copy(source, into, &options).map(OpRes::Write)? + } else if to_inside { + ensure_dir_exists(&into, target_root)?; + ensure_out_of_root(&into)?; + let filename = source.file_name().ok_or_else(|| { + IoError::new( + IoErrorKind::InvalidFilename, + format!("Filename not found for {}", into.display()), + ) + })?; + let into = into.join(filename); + ensure_out_of_root(&into)?; + std::fs::copy(source, into).map(OpRes::Write)? } else { - if to_inside { - ensure_dir_exists(&into, &target_root)?; - ensure_out_of_root(&into)?; - let filename = - source.file_name().ok_or_else(|| { - IoError::new( - IoErrorKind::InvalidFilename, - format!("Filename not found for {}", into.display()), - ) - })?; - let into = into.join(filename); - ensure_out_of_root(&into)?; + let into_parent = parent_of(&into)?; + ensure_dir_exists(into_parent, target_root)?; + ensure_out_of_root(into_parent)?; + + if !into.try_exists()? || overwrite { std::fs::copy(source, into).map(OpRes::Write)? } else { - let into_parent = parent_of(&into)?; - ensure_dir_exists(&into_parent, &target_root)?; - ensure_out_of_root(&into_parent)?; - - if !into.try_exists()? || overwrite { - std::fs::copy(source, into).map(OpRes::Write)? - } else { - OpRes::Skip - } + OpRes::Skip } }; info!(" {copied:?} copy: {} <- {}", target.display(), source.display()); @@ -100,7 +97,7 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, let link_method = |source: &Path, target: &Path, to_inside| -> Result { let into = target_root.join(target); let linked = if to_inside { - ensure_dir_exists(&into, &target_root)?; + ensure_dir_exists(&into, target_root)?; let filename = source.file_name().ok_or_else(|| { IoError::new( @@ -109,12 +106,12 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, ) })?; let into = into.join(filename); - soft_link_checked(source, &into, overwrite, &target_root) + soft_link_checked(source, into, overwrite, target_root) } else { let into_parent = parent_of(&into)?; - ensure_dir_exists(&into_parent, &target_root)?; - soft_link_checked(source, &into, overwrite, &target_root) - }.map(|was| was.then(|| OpRes::Link).unwrap_or_else(|| OpRes::Skip))?; + ensure_dir_exists(into_parent, target_root)?; + soft_link_checked(source, &into, overwrite, target_root) + }.map(|was| if was { OpRes::Link } else { OpRes::Skip })?; info!(" {linked:?} link: {} <- {}", target.display(), source.display()); Ok(linked) }; diff --git a/support/build/src/assets/plan.rs b/support/build/src/assets/plan.rs index 9c63b080..cd71e403 100644 --- a/support/build/src/assets/plan.rs +++ b/support/build/src/assets/plan.rs @@ -48,7 +48,7 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, match assets { PlayDateMetadataAssets::List(vec) => { include_unresolved.extend( - vec.into_iter() + vec.iter() .map(to_relative) .map(Expr::from) .map(|e| enver.expr(e, env)), @@ -152,7 +152,7 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, // filter resolved includes: let is_not_empty = |inc: &Match| !inc.target().as_os_str().is_empty(); let excluded: Vec<_> = resolved.extract_if(|inc| { - let target = target.join(&inc.target()); + let target = target.join(inc.target()); !is_not_empty(inc) || glob_matches_any(&inc.source(), &exclude_globs) || glob_matches_any(&target, &exclude_globs) @@ -238,7 +238,7 @@ impl BuildPlan<'_, '_> { pub fn print(&self) { info!("assets build plan:"); - let print = |inc: &Match, &(ref left, ref right): &(Expr, Expr)| { + let print = |inc: &Match, (left, right): &(Expr, Expr)| { info!( " {} <- {} ({left} = {right})", inc.target().display(), @@ -268,40 +268,40 @@ impl BuildPlan<'_, '_> { } pub fn targets(&self) -> impl Iterator> { - self.as_inner().into_iter().flat_map(|mapping| { - match mapping { - Mapping::AsIs(inc, ..) => vec![inc.target()].into_iter(), - Mapping::Into(inc, ..) => vec![inc.target()].into_iter(), - Mapping::ManyInto { sources, target, .. } => { - sources.into_iter() - .map(|inc| Cow::from(target.join(inc.target()))) - .collect::>() - .into_iter() - }, - } - }) + self.as_inner().iter().flat_map(|mapping| { + match mapping { + Mapping::AsIs(inc, ..) => vec![inc.target()].into_iter(), + Mapping::Into(inc, ..) => vec![inc.target()].into_iter(), + Mapping::ManyInto { sources, target, .. } => { + sources.iter() + .map(|inc| Cow::from(target.join(inc.target()))) + .collect::>() + .into_iter() + }, + } + }) } - pub fn serializable_flatten<'t>( - &'t self) - -> impl Iterator))> + 't { + pub fn serializable_flatten( + &self) + -> impl Iterator))> + '_ { let pair = |inc: &Match| (inc.target().to_path_buf(), inc.source().to_path_buf()); self.as_inner() - .into_iter() + .iter() .flat_map(move |mapping| { let mut rows = Vec::new(); match mapping { Mapping::AsIs(inc, _) | Mapping::Into(inc, _) => rows.push(pair(inc)), Mapping::ManyInto { sources, target, .. } => { - rows.extend(sources.into_iter() + rows.extend(sources.iter() .map(|inc| pair(&Match::new(inc.source(), target.join(inc.target()))))); }, }; rows.into_iter() }) .map(|(t, p)| { - let time = p.metadata().ok().map(|m| m.modified().ok()).flatten(); + let time = p.metadata().ok().and_then(|m| m.modified().ok()); (t, (p, time)) }) } @@ -355,7 +355,7 @@ impl Mapping<'_, '_> { pub fn exprs(&self) -> (&Expr<'_>, &Expr<'_>) { match self { - Mapping::AsIs(_, (left, right)) | Mapping::Into(_, (left, right)) => (&left, &right), + Mapping::AsIs(_, (left, right)) | Mapping::Into(_, (left, right)) => (left, right), Mapping::ManyInto { exprs: (left, right), .. } => (left, right), } } diff --git a/support/build/src/assets/resolver.rs b/support/build/src/assets/resolver.rs index 5fc7940d..c26daac1 100644 --- a/support/build/src/assets/resolver.rs +++ b/support/build/src/assets/resolver.rs @@ -4,7 +4,7 @@ use std::str; use std::path::{Path, PathBuf}; use regex::Regex; -use wax::{Glob, LinkBehavior, WalkError, WalkEntry, BuildError}; +use wax::{Glob, LinkBehavior, WalkError, WalkEntry}; use crate::cargo; use crate::config::Env; @@ -18,16 +18,16 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, links: LinkBehavior) -> Result, Error> { let glob = Glob::new(expr.as_ref())?; - let exclude = exclude.into_iter().map(AsRef::as_ref).chain(["**/.*/**"]); - let walker = glob.walk_with_behavior(&crate_root, links) + let exclude = exclude.iter().map(AsRef::as_ref).chain(["**/.*/**"]); + let walker = glob.walk_with_behavior(crate_root, links) .not(exclude)? - .map(|res| res.map(|entry| Match::from(entry))); + .map(|res| res.map(Match::from)); let files = walker.map(|res| { let mut inc = res.map_err(log_err)?; let target = inc.target(); // modify target path: - if target.is_absolute() && target.starts_with(crate_root) { + let new = if target.is_absolute() && target.starts_with(crate_root) { // make it relative to crate_root: let len = crate_root.components().count(); Some(target.components().skip(len).collect()) @@ -41,7 +41,10 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, } else { // as-is None - }.and_then(|new| Some(inc.set_target(new))); + }; + if let Some(new) = new { + inc.set_target(new) + } Ok::<_, WalkError>(inc) }); @@ -79,7 +82,10 @@ impl EnvResolver { .get(name) .map(Cow::from) .or_else(|| std::env::var(name).map_err(log_err).ok().map(Cow::from)) - .expect(&format!("Env var \"{name}\" not found")); + .unwrap_or_else(|| { + // XXX: should we panic here? + panic!("Env var \"{name}\" not found") + }); replaced = replaced.replace(full, &var); } @@ -99,7 +105,10 @@ impl EnvResolver { let var = std::env::var(name).map_err(log_err) .map(Cow::from) - .expect(&format!("Env var \"{name}\" not found")); + .unwrap_or_else(|_| { + // XXX: should we panic here? + panic!("Env var \"{name}\" not found") + }); replaced = replaced.replace(full, &var); } } @@ -246,13 +255,13 @@ impl AsRef for Expr<'_> { fn as_ref(&self) -> &str { self.actual() } } -impl Into for &Expr<'_> { - fn into(self) -> PathBuf { self.actual().into() } +impl From<&Expr<'_>> for PathBuf { + fn from(expr: &Expr<'_>) -> Self { expr.actual().into() } } -impl Into for Expr<'_> { - fn into(self) -> PathBuf { - let actual: PathBuf = match self { +impl From> for PathBuf { + fn from(expr: Expr<'_>) -> Self { + let actual: PathBuf = match expr { Expr::Original(original) => original.into(), Expr::Modified { actual, .. } => actual.into_owned().into(), }; diff --git a/support/build/src/io.rs b/support/build/src/io.rs index d5c0da30..185887cc 100644 --- a/support/build/src/io.rs +++ b/support/build/src/io.rs @@ -30,10 +30,8 @@ pub fn soft_link_checked, Pl: AsRef>(origin: Po, let existing = link.as_ref().try_exists()?; let symlink = link.as_ref().is_symlink(); - if symlink { - if std::fs::read_link(&link)? == origin.as_ref() { - return Ok(false); - } + if symlink && std::fs::read_link(&link)? == origin.as_ref() { + return Ok(false); } if !existing && !symlink { @@ -67,10 +65,8 @@ pub fn hard_link_forced, Pl: AsRef>(origin: Po, let existing = link.as_ref().try_exists()?; let symlink = link.as_ref().is_symlink(); - if symlink { - if std::fs::read_link(&link)? == origin.as_ref() { - return Ok(false); - } + if symlink && std::fs::read_link(&link)? == origin.as_ref() { + return Ok(false); } if !existing && !symlink { @@ -106,7 +102,7 @@ fn check_top_boundary>(path: &Path, boundary: B) -> Result let path = path.parent() .ok_or_else(|| IoError::new(IoErrorKind::NotFound, format!("Parent of {}", path.display())))?; let (existing, tail) = get_existing_ancestor(path)?; - Ok(existing.starts_with(&boundary) || existing.join(&tail).starts_with(&boundary)) + Ok(existing.starts_with(&boundary) || existing.join(tail).starts_with(&boundary)) } fn check_top_boundary_ok>(path: &Path, boundary: B) -> Result<()> { @@ -124,7 +120,7 @@ fn check_top_boundary_ok>(path: &Path, boundary: B) -> Result<()> /// Returns canonicalized existing part of path, /// and non-existing tail of path. -fn get_existing_ancestor<'p>(path: &'p Path) -> Result<(PathBuf, &'p Path)> { +fn get_existing_ancestor(path: &Path) -> Result<(PathBuf, &Path)> { use std::io::{Error, ErrorKind}; let parent = path.ancestors() @@ -140,7 +136,7 @@ fn get_existing_ancestor<'p>(path: &'p Path) -> Result<(PathBuf, &'p Path)> { let mut parent = parent.canonicalize()?; for (i, comp) in tail.components().enumerate() { - let next = parent.join(&comp); + let next = parent.join(comp); if next.try_exists()? { // Note: this can fail if canonicalizing symlink pointing to nowhere. parent = next.canonicalize()?; diff --git a/support/build/src/manifest.rs b/support/build/src/manifest.rs index 259eeb5c..bc8c940e 100644 --- a/support/build/src/manifest.rs +++ b/support/build/src/manifest.rs @@ -102,7 +102,7 @@ impl<'t, T> TryFrom> for Manifest where T: ManifestDataSource { version: metadata.version .to_owned() .unwrap_or(source.version().to_string()), - build_number: metadata.build_number.as_ref().map(|v| v.parse().ok()).flatten(), + build_number: metadata.build_number.as_ref().and_then(|v| v.parse().ok()), image_path: metadata.image_path.to_owned(), launch_sound_path: metadata.launch_sound_path.to_owned(), content_warning: metadata.content_warning.to_owned(), diff --git a/support/build/src/metadata.rs b/support/build/src/metadata.rs index 6b53a306..23d09b94 100644 --- a/support/build/src/metadata.rs +++ b/support/build/src/metadata.rs @@ -180,7 +180,7 @@ pub mod format { self.options .assets .as_ref() - .map_or_else(Default::default, |ao| Cow::Borrowed(ao)) + .map_or_else(Default::default, Cow::Borrowed) } } diff --git a/support/device/Cargo.toml b/support/device/Cargo.toml index 69558770..a103cc7b 100644 --- a/support/device/Cargo.toml +++ b/support/device/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-device" -version = "0.2.3" +version = "0.2.4" readme = "README.md" description = "Cross-platform interface Playdate device, async & blocking." keywords = ["playdate", "usb", "serial"] @@ -80,7 +80,7 @@ version = "0.1" optional = true [target.'cfg(target_os = "windows")'.dependencies.windows] -version = "0.54.0" +version = "0.56" features = [ "Win32_Foundation", "Win32_Storage", diff --git a/support/device/src/device/command.rs b/support/device/src/device/command.rs index 329a9681..57ce1b9a 100644 --- a/support/device/src/device/command.rs +++ b/support/device/src/device/command.rs @@ -120,7 +120,7 @@ impl Command { Command::Version => "version".into(), Command::Button { button } => format!("btn {}", button.as_btn_str()).into(), Command::Message { message } => format!("msg {message}").into(), - Command::Custom { cmd } => format!("{cmd}").into(), + Command::Custom { cmd } => cmd.into(), } } } @@ -163,9 +163,9 @@ impl From for Switch { fn from(value: bool) -> Self { if value { Switch::On } else { Switch::Off } } } -impl Into for Switch { - fn into(self) -> bool { - match self { +impl From for bool { + fn from(val: Switch) -> Self { + match val { Switch::On => true, Switch::Off => false, } diff --git a/support/device/src/device/serial.rs b/support/device/src/device/serial.rs index e07a9375..cc663a5e 100644 --- a/support/device/src/device/serial.rs +++ b/support/device/src/device/serial.rs @@ -16,8 +16,8 @@ impl SerialNumber { let re = Regex::new(REGEX_NAME).expect("invalid regex"); let captures = re.captures(s.as_ref())?; let serial = Self::unify(captures.get(1)?.as_str()); - let serial = if serial.contains("_") { - serial.replace("_", "-") + let serial = if serial.contains('_') { + serial.replace('_', "-") } else { serial.to_string() }; @@ -28,8 +28,8 @@ impl SerialNumber { fn unify<'s, S: Into>>(s: S) -> Cow<'s, str> { let s = s.into(); - if s.contains("_") { - s.replace("_", "-").into() + if s.contains('_') { + s.replace('_', "-").into() } else { s } diff --git a/support/device/src/install.rs b/support/device/src/install.rs index ad642ee2..e64a5970 100644 --- a/support/device/src/install.rs +++ b/support/device/src/install.rs @@ -27,7 +27,7 @@ pub struct MountedDevicePathBorrowed<'dev> { } impl<'dev> MountedDevicePathBorrowed<'dev> { - pub fn drive(&self) -> &MountedDevice { &self.drive } + pub fn drive(&self) -> &MountedDevice { self.drive } /// Local on-device path. pub fn path_local(&self) -> &str { &self.path } diff --git a/support/device/src/mount/mac.rs b/support/device/src/mount/mac.rs index 24b9c1fa..498e984f 100644 --- a/support/device/src/mount/mac.rs +++ b/support/device/src/mount/mac.rs @@ -89,7 +89,7 @@ pub struct SpusbInfo pub async fn volume_for(dev: Info) -> Result where Info: AsRef { if let Some(sn) = dev.as_ref().serial_number() { - let res = spusb(move |ref info| info.serial_num == sn).map(|mut iter| iter.next().map(|info| info.volume)); + let res = spusb(move |info| info.serial_num == sn).map(|mut iter| iter.next().map(|info| info.volume)); match res { Ok(None) => Err(Error::not_found()), Ok(Some(fut)) => Ok(fut), @@ -106,11 +106,10 @@ pub async fn volumes_for_map(devs: I) -> Result { let mut devs = devs.into_iter() .filter_map(|dev| { - if let Some(sn) = dev.info().serial_number().map(ToOwned::to_owned) { - Some((dev, sn)) - } else { - None - } + dev.info() + .serial_number() + .map(ToOwned::to_owned) + .map(|sn| (dev, sn)) }) .collect::>(); @@ -181,7 +180,7 @@ fn spusb(filter: F) serial_num: serial, media, .. } = item; - let volume = media.map(|media| { + let volume = media.and_then(|media| { media.into_iter() .flat_map(|root| root.volumes.into_iter()) .filter_map(|par| { @@ -202,8 +201,7 @@ fn spusb(filter: F) } }) .next() - }) - .flatten(); + }); volume.map(|volume| SpusbInfo { name, serial, volume }) }); Ok(result) diff --git a/support/device/src/retry.rs b/support/device/src/retry.rs index c94c14d4..cbadb9bf 100644 --- a/support/device/src/retry.rs +++ b/support/device/src/retry.rs @@ -57,7 +57,7 @@ impl IterTime for &'_ T { } pub fn calc_interval(wait: &Duration, cfg: T) -> Duration { - let iters = wait.as_millis() / cfg.preferred_iter_time().as_millis() as u128; + let iters = wait.as_millis() / cfg.preferred_iter_time().as_millis(); Duration::from_millis((wait.as_millis() / iters) as _) } @@ -81,7 +81,7 @@ impl std::fmt::Debug for DefaultIterTime { impl IterTime for Duration { - fn preferred_iter_time(&self) -> Duration { self.clone() } + fn preferred_iter_time(&self) -> Duration { *self } fn interval(&self, total_wait: &Duration) -> Duration where for<'t> &'t Self: IterTime { diff --git a/support/device/src/serial/mod.rs b/support/device/src/serial/mod.rs index 1a409d78..4d0dfd14 100644 --- a/support/device/src/serial/mod.rs +++ b/support/device/src/serial/mod.rs @@ -28,15 +28,11 @@ impl std::fmt::Display for Interface { use serialport::SerialPort; let port_name = &self.info.port_name; - let name = self.port - .as_ref() - .map(|p| { - p.try_borrow() - .ok() - .map(|p| p.name().filter(|s| s != port_name)) - .flatten() - }) - .flatten(); + let name = self.port.as_ref().and_then(|p| { + p.try_borrow() + .ok() + .and_then(|p| p.name().filter(|s| s != port_name)) + }); write!(f, "serial:{}", name.as_deref().unwrap_or(port_name)) } diff --git a/support/device/src/usb/discover.rs b/support/device/src/usb/discover.rs index 1b2f949f..77cff73e 100644 --- a/support/device/src/usb/discover.rs +++ b/support/device/src/usb/discover.rs @@ -18,7 +18,7 @@ type Result = std::result::Result; #[cfg_attr(feature = "tracing", tracing::instrument)] pub fn devices() -> Result> { Ok(nusb::list_devices()?.filter(|d| d.vendor_id() == VENDOR_ID) - .map(|info| Device::new(info))) + .map(Device::new)) } /// Search Playdate- devices that in data (serial/modem/telnet) mode. diff --git a/support/device/src/usb/io.rs b/support/device/src/usb/io.rs index dee31828..5e3526e8 100644 --- a/support/device/src/usb/io.rs +++ b/support/device/src/usb/io.rs @@ -35,7 +35,7 @@ pub fn read_interface(interface: &Interface, inp.submit(RequestBuffer::reuse(data, buf_size)); Ok(s) }) - .map(|out| Some(out)) + .map(Some) }); Ok(stream) @@ -94,7 +94,7 @@ pub fn read_once(device: DeviceInfo) -> Result<(String, Interface), Error> { let inter = device.claim_interface(1)?; let stream = read_while_map(&inter, 256, 2, |data| { - match std::str::from_utf8(&data) { + match std::str::from_utf8(data) { Ok(s) => { if s.trim().is_empty() { None diff --git a/support/device/src/usb/mod.rs b/support/device/src/usb/mod.rs index ece50d64..98261a90 100644 --- a/support/device/src/usb/mod.rs +++ b/support/device/src/usb/mod.rs @@ -194,17 +194,17 @@ impl Device { let mut errors = Vec::new(); let port = { - crate::serial::discover::ports_for(&self).map(|ports| ports.map(|port| Interface::new(port)))? - .find_map(|mut port| { - // try to open port, we could get an permission error - match port.open() { - Ok(_) => Some(port), - Err(err) => { - errors.push(err); - None - }, - } - }) + crate::serial::discover::ports_for(self).map(|ports| ports.map(Interface::new))? + .find_map(|mut port| { + // try to open port, we could get an permission error + match port.open() { + Ok(_) => Some(port), + Err(err) => { + errors.push(err); + None + }, + } + }) }; if let Some(port) = port { diff --git a/support/sim-ctrl/Cargo.toml b/support/sim-ctrl/Cargo.toml index f7e45da6..3fec5466 100644 --- a/support/sim-ctrl/Cargo.toml +++ b/support/sim-ctrl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-simulator-utils" -version = "0.1.3" +version = "0.1.4" readme = "README.md" description = "Cross-platform utils to deal with Playdate Simulator." keywords = ["playdate", "sdk", "utils"] diff --git a/support/sim-ctrl/src/run.rs b/support/sim-ctrl/src/run.rs index dc150ea3..6747fc20 100644 --- a/support/sim-ctrl/src/run.rs +++ b/support/sim-ctrl/src/run.rs @@ -12,7 +12,7 @@ pub async fn run(pdx: &Path, sdk: Option<&Path>) -> Result<(), Error> { use async_std::process::Command; #[allow(unused_mut)] - let mut cmd = command(&pdx, sdk.as_deref())?; + let mut cmd = command(pdx, sdk)?; #[cfg(any(feature = "tokio", feature = "async-std"))] let mut cmd = Command::from(cmd); @@ -29,7 +29,7 @@ pub async fn run(pdx: &Path, sdk: Option<&Path>) -> Result<(), Error> { #[cfg_attr(feature = "tracing", tracing::instrument)] pub fn command(pdx: &Path, sdk: Option<&Path>) -> Result { - let sdk = sdk.map_or_else(|| Sdk::try_new(), Sdk::try_new_exact)?; + let sdk = sdk.map_or_else(Sdk::try_new, Sdk::try_new_exact)?; let (pwd, sim) = if cfg!(target_os = "macos") { ("Playdate Simulator.app/Contents/MacOs", "./Playdate Simulator") @@ -43,7 +43,7 @@ pub fn command(pdx: &Path, sdk: Option<&Path>) -> Result Result, Error> { match self.lib_search_paths_for::<&str, _>([]) { Ok(paths) if !paths.is_empty() => Ok(paths), - Ok(_) | Err(_) => Ok(vec![self.gcc().sysroot().and_then(|p| Ok(p.join("lib")))?]), + Ok(_) | Err(_) => Ok(vec![self.gcc().sysroot().map(|p| p.join("lib"))?]), } } @@ -324,16 +318,16 @@ pub mod err { Error::Utf8(err) => err.fmt(f), Error::Err(err) => err.fmt(f), Error::ExitStatusError { cmd, status, stderr } => { - let stderr = std::str::from_utf8(&stderr).map(str::trim) - .map(|s| format!("with output: {s}")) - .ok() - .unwrap_or_else(|| { - if stderr.is_empty() { - "without output".into() - } else { - "with not decodable output".into() - } - }); + let stderr = std::str::from_utf8(stderr).map(str::trim) + .map(|s| format!("with output: {s}")) + .ok() + .unwrap_or_else(|| { + if stderr.is_empty() { + "without output".into() + } else { + "with not decodable output".into() + } + }); write!(f, "ExitStatusError: ({status}) {cmd} {stderr}.",) }, } diff --git a/support/utils/src/toolchain/sdk.rs b/support/utils/src/toolchain/sdk.rs index ce1a9d2e..c9e7062e 100644 --- a/support/utils/src/toolchain/sdk.rs +++ b/support/utils/src/toolchain/sdk.rs @@ -25,7 +25,7 @@ impl Sdk { pub fn pdc(&self) -> PathBuf { #[cfg(unix)] - const PDC: &'static str = "pdc"; + const PDC: &str = "pdc"; #[cfg(windows)] const PDC: &'static str = "PDC.EXE"; self.bin().join(PDC) @@ -33,7 +33,7 @@ impl Sdk { pub fn pdutil(&self) -> PathBuf { #[cfg(unix)] - const PDUTIL: &'static str = "pdutil"; + const PDUTIL: &str = "pdutil"; #[cfg(windows)] const PDUTIL: &'static str = "PDUTIL.EXE"; self.bin().join(PDUTIL) @@ -113,7 +113,7 @@ impl Sdk { /// Create new `Sdk` with default env var pub fn try_from_default_path() -> Result { #[cfg(unix)] - const SDK_HOME_DIR: &'static str = "Developer"; + const SDK_HOME_DIR: &str = "Developer"; #[cfg(windows)] const SDK_HOME_DIR: &'static str = "Documents"; @@ -123,7 +123,7 @@ impl Sdk { #[cfg(unix)] pub fn try_xdg_unix_path() -> Result { - const XDG_CONFIG_DATA_ENV: &'static str = "XDG_CONFIG_DATA"; + const XDG_CONFIG_DATA_ENV: &str = "XDG_CONFIG_DATA"; let xdg_data_path = match std::env::var(XDG_CONFIG_DATA_ENV) { Ok(ref variable) => PathBuf::from(variable), @@ -174,12 +174,12 @@ mod config { use std::str::FromStr; #[cfg(unix)] - const DEFAULT_XDG_CONFIG_DIR: &'static str = ".config"; + const DEFAULT_XDG_CONFIG_DIR: &str = ".config"; #[cfg(unix)] - const XDG_CONFIG_HOME_ENV: &'static str = "XDG_CONFIG_HOME"; - const CFG_DIR: &'static str = ".Playdate"; - const CFG_FILENAME: &'static str = "config"; - const CFG_KEY_SDK_ROOT: &'static str = "SDKRoot"; + const XDG_CONFIG_HOME_ENV: &str = "XDG_CONFIG_HOME"; + const CFG_DIR: &str = ".Playdate"; + const CFG_FILENAME: &str = "config"; + const CFG_KEY_SDK_ROOT: &str = "SDKRoot"; pub(super) struct Cfg(HashMap); @@ -206,7 +206,7 @@ mod config { return Ok(cfg_path); } - return Err(Error::new(std::io::ErrorKind::NotFound, "Config file not found")); + Err(Error::new(std::io::ErrorKind::NotFound, "Config file not found")) } std::fs::read_to_string(find_config_folder()?)?.parse() @@ -222,7 +222,7 @@ mod config { Ok(Self( s.trim() .lines() - .filter_map(|line| line.split_once("\t").map(|(k, v)| (k.to_owned(), v.to_owned()))) + .filter_map(|line| line.split_once('\t').map(|(k, v)| (k.to_owned(), v.to_owned()))) .collect(), )) }