From ad1b46ed1700a7e2981c1c75c4558b4d954138ba Mon Sep 17 00:00:00 2001 From: gustavo-shigueo Date: Thu, 25 Jul 2024 10:20:35 -0300 Subject: [PATCH] Fix double header error --- ts-rs/src/export.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ts-rs/src/export.rs b/ts-rs/src/export.rs index 99e5476e..03374d81 100644 --- a/ts-rs/src/export.rs +++ b/ts-rs/src/export.rs @@ -158,9 +158,9 @@ fn export_and_merge(path: PathBuf, type_name: String, generated_type: String) -> .write(true) .open(&path)?; - let file_len = file.metadata()?.len() as usize; + let file_len = file.metadata()?.len(); - let mut original_contents = String::with_capacity(file_len); + let mut original_contents = String::with_capacity(file_len as usize); file.read_to_string(&mut original_contents)?; let buffer = merge(original_contents, generated_type); @@ -189,9 +189,9 @@ fn merge(original_contents: String, new_contents: String) -> String { let (new_header, new_decl) = new_contents.split_once("\n\n").expect(HEADER_ERROR_MESSAGE); let imports = original_header - .trim_start_matches(NOTE) .lines() - .chain(new_header.trim_start_matches(NOTE).lines()) + .skip(1) + .chain(new_header.lines().skip(1)) .collect::>(); let import_len = imports.iter().map(|&x| x.len()).sum::() + imports.len();