这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: lifetime notation #798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/tuono/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 8 additions & 10 deletions crates/tuono/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct GithubTreeResponse<T> {
}

fn exit_with_error(message: &str) -> ! {
eprintln!("{}", message);
eprintln!("{message}");
std::process::exit(1);
}

Expand Down Expand Up @@ -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, ..
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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}\""),
Expand All @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tuono/src/process_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!());
Expand Down
27 changes: 10 additions & 17 deletions crates/tuono/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,22 @@ 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();

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}"
));
}
}
Expand All @@ -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
Expand All @@ -214,17 +210,15 @@ 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:?}"
));
}
};

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}"
));
}
}
Expand Down Expand Up @@ -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:?}"
));
}
};
Expand All @@ -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"))
}
}

Expand Down
18 changes: 9 additions & 9 deletions crates/tuono/src/typescript/parser/parse_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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!(
Expand All @@ -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");
Expand All @@ -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!(
Expand Down
8 changes: 4 additions & 4 deletions crates/tuono/tests/cli_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);
}
Expand All @@ -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);
}
Expand Down
7 changes: 3 additions & 4 deletions crates/tuono/tests/utils/mock_github_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions crates/tuono_internal/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions crates/tuono_lib/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion crates/tuono_lib/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions crates/tuono_lib/src/vite_reverse_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/tuono_lib_macros/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);

Expand Down
Loading