Skip to content

Commit

Permalink
Fix double header error
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-shigueo committed Jul 25, 2024
1 parent dedfba5 commit ad1b46e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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::<BTreeSet<_>>();

let import_len = imports.iter().map(|&x| x.len()).sum::<usize>() + imports.len();
Expand Down

0 comments on commit ad1b46e

Please sign in to comment.