Upgrade to rust stable 1.76.0 and fix clippy errors

This commit is contained in:
Brian Picciano 2024-02-27 11:30:28 +01:00
parent e416a76668
commit f562b32edb
11 changed files with 107 additions and 108 deletions

View File

@ -2,15 +2,17 @@
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1699770036,
"narHash": "sha256-bZmI7ytPAYLpyFNgj5xirDkKuAniOkj1xHdv5aIJ5GM=",
"lastModified": 1708928609,
"narHash": "sha256-LcXC2NP/TzHMmJThZGG1e+7rht5HeuZK5WOirIDg+lU=",
"owner": "nix-community",
"repo": "fenix",
"rev": "81ab0b4f7ae9ebb57daa0edf119c4891806e4d3a",
"rev": "e928fb6b5179ebd032c19afac5c461ccc0b6de55",
"type": "github"
},
"original": {
@ -21,7 +23,7 @@
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs_2"
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1690373729,
@ -39,22 +41,6 @@
}
},
"nixpkgs": {
"locked": {
"lastModified": 1699099776,
"narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1691003216,
"narHash": "sha256-Qq/MPkhS12Bl0X060pPvX3v9ac3f2rRQfHjjozPh/Qs=",
@ -68,7 +54,7 @@
"type": "indirect"
}
},
"nixpkgs_3": {
"nixpkgs_2": {
"locked": {
"lastModified": 1688392541,
"narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=",
@ -88,17 +74,17 @@
"inputs": {
"fenix": "fenix",
"naersk": "naersk",
"nixpkgs": "nixpkgs_3"
"nixpkgs": "nixpkgs_2"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1699715108,
"narHash": "sha256-yPozsobJU55gj+szgo4Lpcg1lHvGQYAT6Y4MrC80mWE=",
"lastModified": 1708878562,
"narHash": "sha256-IBHMNEe3lspVdIzjpM2OVZiBFmFw1DKtdgVN5G41pRc=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "5fcf5289e726785d20d3aa4d13d90a43ed248e83",
"rev": "5346002d07d09badaf37949bec68012d963d61fc",
"type": "github"
},
"original": {

View File

@ -1,6 +1,7 @@
{
inputs = {
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
};
@ -119,9 +120,8 @@
# TODO I'd prefer to use the toolchain file
# https://github.com/nix-community/fenix/issues/123
fenixToolchain = fenixTarget: (builtins.getAttr "toolchainOf" fenixTarget) {
channel = "nightly";
date = "2023-07-23";
sha256 = "sha256-LU4C/i+maIOqBZagUaXpFyWZyOVfQ3Ah5/JTz7v6CG4=";
channel = "1.76.0";
sha256 = "sha256-e4mlaJehWBymYxJGgnbuCObVlqMlQSilZ8FljG9zPHY=";
};
in
fenixPkgs.combine [

View File

@ -1,6 +1,6 @@
[toolchain]
channel = "nightly-2023-07-23"
components = [ "rustfmt", "rustc-dev", "clippy", "cargo" ]
channel = "1.76.0"
components = [ "rustfmt", "rustc-dev", "clippy", "cargo", "rust-std" ]
targets = [
"x86_64-unknown-linux-musl",
"i686-unknown-linux-musl",

View File

@ -136,10 +136,11 @@ impl Manager for ManagerImpl {
let thirty_days = openssl::asn1::Asn1Time::days_from_now(30)
.expect("parsed thirty days from now as Asn1Time");
let cert_with_soonest_not_after = certs
let cert_with_soonest_not_after = util::try_collect(
certs
.into_iter()
.map(|cert| openssl::x509::X509::try_from(&cert))
.try_collect::<Vec<openssl::x509::X509>>()
.map(|cert| openssl::x509::X509::try_from(&cert)),
)
.or_unexpected_while("parsing x509 certs")?
.into_iter()
.reduce(|a, b| if a.not_after() < b.not_after() { a } else { b })
@ -304,7 +305,8 @@ impl Manager for ManagerImpl {
// Download the certificate, and panic if it doesn't exist.
log::info!("Fetching certificate for domain {}", domain.as_str());
let certs = order
let certs = util::try_collect(
order
.certificate()
.await
.or_unexpected_while("fetching certificate")?
@ -312,8 +314,8 @@ impl Manager for ManagerImpl {
"expected the order to return a certificate",
))?
.into_iter()
.map(|cert| Certificate::try_from(cert.as_ref()))
.try_collect::<Vec<Certificate>>()
.map(|cert| Certificate::try_from(cert.as_ref())),
)
.or_unexpected_while("parsing certificate")?;
if certs.len() <= 1 {

View File

@ -6,13 +6,9 @@ fn addr_from_url(
expected_scheme: &str,
default_port: u16,
) -> unexpected::Result<String> {
let parsed: http::Uri = url
.parse()
.map_unexpected_while(|| format!("could not parse as url"))?;
let parsed: http::Uri = url.parse().or_unexpected_while("could not parse as url")?;
let scheme = parsed
.scheme()
.map_unexpected_while(|| format!("scheme is missing"))?;
let scheme = parsed.scheme().or_unexpected_while("scheme is missing")?;
if scheme != expected_scheme {
return Err(unexpected::Error::from(

View File

@ -4,6 +4,15 @@ use crate::{origin, task_stack, util};
use std::sync;
fn collect_into<I, V>(into: &mut Vec<V>, iter: I)
where
I: std::iter::Iterator<Item = V>,
{
for v in iter {
into.push(v)
}
}
pub enum GetSettingsResult {
Stored(domain::Settings),
Builtin(domain::config::ConfigBuiltinDomain),
@ -477,23 +486,27 @@ impl Manager for ManagerImpl {
})
.collect();
collect_into(
&mut res,
self.config
.builtin_domains
.iter()
.map(|(domain, config)| ManagedDomain {
domain: domain.clone(),
public: config.public,
})
.collect_into(&mut res);
}),
);
collect_into(
&mut res,
self.config
.proxied_domains
.keys()
.map(|domain| ManagedDomain {
domain: domain.clone(),
public: false,
})
.collect_into(&mut res);
}),
);
if let Some(ref interface_domain) = self.config.interface_domain {
res.push(ManagedDomain {
@ -502,14 +515,16 @@ impl Manager for ManagerImpl {
})
}
collect_into(
&mut res,
self.config
.external_domains
.keys()
.map(|domain| ManagedDomain {
domain: domain.clone(),
public: false,
})
.collect_into(&mut res);
}),
);
Ok(res)
}

View File

@ -72,9 +72,7 @@ impl Store for FSStore {
}
fn all_domains(&self) -> unexpected::Result<Vec<domain::Name>> {
fs::read_dir(&self.dir_path)
.or_unexpected()?
.map(
let domains = fs::read_dir(&self.dir_path).or_unexpected()?.map(
|dir_entry_res: io::Result<fs::DirEntry>| -> unexpected::Result<domain::Name> {
let domain = dir_entry_res.or_unexpected()?.file_name();
let domain = domain.to_str().ok_or(unexpected::Error::from(
@ -85,8 +83,9 @@ impl Store for FSStore {
.parse()
.map_unexpected_while(|| format!("parsing {domain} as domain name"))
},
)
.try_collect()
);
crate::util::try_collect(domains.into_iter())
}
}

View File

@ -1,7 +1,3 @@
#![feature(result_option_inspect)]
#![feature(iterator_try_collect)]
#![feature(iter_collect_into)]
pub mod config;
pub mod domain;
pub mod origin;

View File

@ -1,5 +1,3 @@
#![feature(trait_upcasting)]
use clap::Parser;
use std::path;

View File

@ -13,13 +13,9 @@ pub struct GitUrl {
impl std::str::FromStr for GitUrl {
type Err = unexpected::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let parsed: http::Uri = s
.parse()
.map_unexpected_while(|| format!("parsing as url"))?;
let parsed: http::Uri = s.parse().or_unexpected_while("parsing as url")?;
let scheme = parsed
.scheme()
.map_unexpected_while(|| format!("extracting scheme"))?;
let scheme = parsed.scheme().or_unexpected_while("extracting scheme")?;
if scheme != "http" && scheme != "https" {
return Err(unexpected::Error::from(

View File

@ -68,3 +68,14 @@ impl BoxByteStream {
}
pub type BoxFuture<'a, O> = pin::Pin<Box<dyn futures::Future<Output = O> + Send + 'a>>;
pub fn try_collect<I, V, E>(iter: I) -> Result<Vec<V>, E>
where
I: std::iter::Iterator<Item = Result<V, E>>,
{
let mut res = Vec::<V>::new();
for v in iter {
res.push(v?);
}
Ok(res)
}