fix: lifetime notation (#798)

This commit is contained in:
Valerio Ageno
2025-07-19 17:49:49 +02:00
committed by GitHub
parent 5990cf3d27
commit a1f5811eda
12 changed files with 49 additions and 54 deletions
+2 -3
View File
@@ -164,10 +164,9 @@ impl App {
std::net::TcpListener::bind(format!("{}:{}", config.server.host, vite_port));
if let Err(_e) = vite_listener {
eprintln!("Error: Failed to bind to port {}", vite_port);
eprintln!("Error: Failed to bind to port {vite_port}");
eprintln!(
"Please ensure that port {} is not already in use by another process or application.",
vite_port
"Please ensure that port {vite_port} is not already in use by another process or application."
);
std::process::exit(1);
}
+8 -10
View File
@@ -33,7 +33,7 @@ struct GithubTreeResponse<T> {
}
fn exit_with_error(message: &str) -> ! {
eprintln!("{}", message);
eprintln!("{message}");
std::process::exit(1);
}
@@ -125,7 +125,7 @@ pub fn create_new_project(
let folder_path = current_dir.join(folder_name);
create_directories(&new_project_files, &folder_path, &template)
.unwrap_or_else(|err| exit_with_error(&format!("Failed to create directories: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to create directories: {err}")));
for GithubFile {
element_type, path, ..
@@ -231,19 +231,17 @@ fn update_package_json_version(folder_path: &Path) -> io::Result<()> {
let v = crate_version!();
let package_json_path = folder_path.join(PathBuf::from("package.json"));
let package_json = fs::read_to_string(&package_json_path)
.unwrap_or_else(|err| exit_with_error(&format!("Failed to read package.json: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to read package.json: {err}")));
let package_json = package_json.replace("link:../../packages/tuono", v);
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.open(package_json_path)
.unwrap_or_else(|err| exit_with_error(&format!("Failed to open package.json: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to open package.json: {err}")));
file.write_all(package_json.as_bytes())
.unwrap_or_else(|err| {
exit_with_error(&format!("Failed to write to package.json: {}", err))
});
.unwrap_or_else(|err| exit_with_error(&format!("Failed to write to package.json: {err}")));
Ok(())
}
@@ -252,7 +250,7 @@ fn update_cargo_toml_version(folder_path: &Path) -> io::Result<()> {
let v = crate_version!();
let cargo_toml_path = folder_path.join(PathBuf::from("Cargo.toml"));
let cargo_toml = fs::read_to_string(&cargo_toml_path)
.unwrap_or_else(|err| exit_with_error(&format!("Failed to read Cargo.toml: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to read Cargo.toml: {err}")));
let cargo_toml = cargo_toml.replace(
"{ path = \"../../crates/tuono_lib/\" }",
&format!("\"{v}\""),
@@ -262,10 +260,10 @@ fn update_cargo_toml_version(folder_path: &Path) -> io::Result<()> {
.write(true)
.truncate(true)
.open(cargo_toml_path)
.unwrap_or_else(|err| exit_with_error(&format!("Failed to open Cargo.toml: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to open Cargo.toml: {err}")));
file.write_all(cargo_toml.as_bytes())
.unwrap_or_else(|err| exit_with_error(&format!("Failed to write to Cargo.toml: {}", err)));
.unwrap_or_else(|err| exit_with_error(&format!("Failed to write to Cargo.toml: {err}")));
Ok(())
}
+1 -1
View File
@@ -94,7 +94,7 @@ impl ProcessManager {
let server_address = format!("{}:{}", config.server.host, config.server.port);
// Format the server address as a valid URL so that it becomes clickable in the CLI
// @see https://github.com/tuono-labs/tuono/issues/460
let server_base_url = format!("http://{}", server_address);
let server_base_url = format!("http://{server_address}");
println!();
tuono_println!("⚡ Tuono v{}", crate_version!());
+10 -17
View File
@@ -169,7 +169,7 @@ impl Route {
trace!("Requesting the page: {}", url);
let mut response = match reqwest.get(format!("http://localhost:3000{path}")).send() {
Ok(response) => response,
Err(_) => return Err(format!("Failed to get the response: {}", url)),
Err(_) => return Err(format!("Failed to get the response: {url}")),
};
let file_path = self.output_file_path();
@@ -177,18 +177,14 @@ impl Route {
let parent_dir = match file_path.parent() {
Some(parent_dir) => parent_dir,
None => {
return Err(format!(
"Failed to get the parent directory {:?}",
file_path
));
return Err(format!("Failed to get the parent directory {file_path:?}"));
}
};
if !parent_dir.is_dir() {
if let Err(err) = create_all(parent_dir, false) {
return Err(format!(
"Failed to create the parent directory {:?}\nError: {err}",
parent_dir
"Failed to create the parent directory {parent_dir:?}\nError: {err}"
));
}
}
@@ -197,11 +193,11 @@ impl Route {
let mut file = match File::create(&file_path) {
Ok(file) => file,
Err(_) => return Err(format!("Failed to create the file: {:?}", file_path)),
Err(_) => return Err(format!("Failed to create the file: {file_path:?}")),
};
if io::copy(&mut response, &mut file).is_err() {
return Err(format!("Failed to write the file: {:?}", file_path));
return Err(format!("Failed to write the file: {file_path:?}"));
}
// Saving also the server response
@@ -214,8 +210,7 @@ impl Route {
Some(parent_dir) => parent_dir,
None => {
return Err(format!(
"Failed to get the parent directory {:?}",
data_file_path
"Failed to get the parent directory {data_file_path:?}"
));
}
};
@@ -223,8 +218,7 @@ impl Route {
if !data_parent_dir.is_dir() {
if let Err(err) = create_all(data_parent_dir, false) {
return Err(format!(
"Failed to create the parent directory {:?}\n Error: {err}",
data_parent_dir
"Failed to create the parent directory {data_parent_dir:?}\n Error: {err}"
));
}
}
@@ -253,8 +247,7 @@ impl Route {
Ok(file) => file,
Err(_) => {
return Err(format!(
"Failed to create the JSON file: {:?}",
data_file_path
"Failed to create the JSON file: {data_file_path:?}"
));
}
};
@@ -274,10 +267,10 @@ impl Route {
.iter()
.any(|extension| self.path.ends_with(extension))
{
return PathBuf::from(format!("out/static{}", cleaned_path));
return PathBuf::from(format!("out/static{cleaned_path}"));
}
PathBuf::from(format!("out/static{}/index.html", cleaned_path))
PathBuf::from(format!("out/static{cleaned_path}/index.html"))
}
}
@@ -22,7 +22,7 @@ pub fn parse_enum(element: &syn::ItemEnum) -> (String, String) {
match &variant.fields {
syn::Fields::Named(field) => {
parsed_variant = format!("{{\"{}\": {{ ", parsed_variant);
parsed_variant = format!("{{\"{parsed_variant}\": {{ ");
let mut variant_fields: Vec<String> = Vec::new();
for field in &field.named {
@@ -79,7 +79,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (enum_name, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(enum_name, "MyEnum");
@@ -101,7 +101,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (enum_name, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(enum_name, "MyEnum");
@@ -125,7 +125,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (_, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(
@@ -147,7 +147,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (_, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(
@@ -167,7 +167,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (_, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(
@@ -187,7 +187,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (_, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(
@@ -209,7 +209,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (enum_name, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(enum_name, "MyEnum");
@@ -229,7 +229,7 @@ mod tests {
}
"#;
let parsed_enum = syn::parse_str::<syn::ItemEnum>(&enum_str).unwrap();
let parsed_enum = syn::parse_str::<syn::ItemEnum>(enum_str).unwrap();
let (_, typescript_definition) = parse_enum(&parsed_enum);
assert_eq!(
+4 -4
View File
@@ -114,11 +114,11 @@ fn it_successfully_import_mixed_case_routes() {
for method in ["get", "post", "put", "delete", "patch"] {
temp_tuono_project.add_file_with_content(
&format!("./src/routes/api/{}_lower.rs", method),
&format!(r"#[tuono_lib::api({})]", method),
&format!("./src/routes/api/{method}_lower.rs"),
&format!(r"#[tuono_lib::api({method})]"),
);
temp_tuono_project.add_file_with_content(
&format!("./src/routes/api/{}_upper.rs", method),
&format!("./src/routes/api/{method}_upper.rs"),
&format!(r"#[tuono_lib::api({})]", method.to_uppercase()),
);
}
@@ -136,7 +136,7 @@ fn it_successfully_import_mixed_case_routes() {
fs::read_to_string(&temp_main_rs_path).expect("Failed to read '.tuono/main.rs' content.");
for method in ["get", "post", "put", "delete", "patch"] {
let expected = format!(r#"use tuono_lib::axum::routing::{};"#, method);
let expected = format!(r#"use tuono_lib::axum::routing::{method};"#);
let imports = temp_main_rs_content.match_indices(&expected);
assert_eq!(imports.count(), 1);
}
@@ -24,9 +24,8 @@ impl GitHubServerMock {
);
Mock::given(method("GET"))
.and(path(&format!(
"repos/tuono-labs/tuono/git/ref/tags/v{}",
tuono_version
.and(path(format!(
"repos/tuono-labs/tuono/git/ref/tags/v{tuono_version}"
)))
.respond_with(sha_response_template)
.mount(&server)
@@ -57,7 +56,7 @@ impl GitHubServerMock {
);
Mock::given(method("GET"))
.and(path(&format!("repos/tuono-labs/tuono/git/trees/{}", sha)))
.and(path(format!("repos/tuono-labs/tuono/git/trees/{sha}")))
.respond_with(tree_response_template)
.mount(&server)
.await;
+6
View File
@@ -13,6 +13,12 @@ pub struct TempTuonoProject {
temp_dir: TempDir,
}
impl Default for TempTuonoProject {
fn default() -> Self {
Self::new()
}
}
impl TempTuonoProject {
pub fn new() -> Self {
let original_dir = env::current_dir().expect("Failed to read current_dir");
+2 -2
View File
@@ -16,9 +16,9 @@ pub unsafe fn load_env_vars(mode: Mode) {
Mode::Prod => "production",
};
env_files.push(format!(".env.{}", mode_name));
env_files.push(format!(".env.{mode_name}"));
env_files.push(String::from(".env.local"));
env_files.push(format!(".env.{}.local", mode_name));
env_files.push(format!(".env.{mode_name}.local"));
let system_env_names: HashSet<String> = env::vars().map(|(k, _)| k).collect();
+1 -1
View File
@@ -120,7 +120,7 @@ mod tests {
}
}"#;
fn prepare_payload(uri: Option<&str>, mode: Mode) -> Payload {
fn prepare_payload(uri: Option<&str>, mode: Mode) -> Payload<'_> {
let manifest_mock = serde_json::from_str::<ViteManifest>(MANIFEST_EXAMPLE)
.expect("Failed to parse the manifest example");
MANIFEST.get_or_init(|| manifest_mock.into());
+2 -2
View File
@@ -26,14 +26,14 @@ pub async fn vite_reverse_proxy(
let query_string = query
.0
.iter()
.map(|(k, v)| format!("{}={}", k, v))
.map(|(k, v)| format!("{k}={v}"))
.collect::<Vec<_>>()
.join("&");
let query_string = if query_string.is_empty() {
String::new()
} else {
format!("?{}", query_string)
format!("?{query_string}")
};
match client
+1 -1
View File
@@ -15,7 +15,7 @@ pub fn api_core(attrs: TokenStream, item: TokenStream) -> TokenStream {
.to_lowercase();
let api_fn_name = Ident::new(
&format!("{}_tuono_internal_api", http_method),
&format!("{http_method}_tuono_internal_api"),
Span::call_site().into(),
);