diff options
| author | lukeflo | 2024-11-06 21:07:38 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-06 21:07:38 +0100 |
| commit | e1923e83711f6d06e994167a83155fbcdd80cd80 (patch) | |
| tree | 4850ee035a8aff81e31eba02de6e5bb4118f0abd /src | |
| parent | c7034560c408f48a16a10546ed8d04ae879ab9ef (diff) | |
| download | bibiman-e1923e83711f6d06e994167a83155fbcdd80cd80.tar.gz bibiman-e1923e83711f6d06e994167a83155fbcdd80cd80.zip | |
replace some cloning with references
Diffstat (limited to 'src')
| -rw-r--r-- | src/bibiman.rs | 12 | ||||
| -rw-r--r-- | src/bibiman/bibisetup.rs | 13 | ||||
| -rw-r--r-- | src/bibiman/entries.rs | 24 |
3 files changed, 24 insertions, 25 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs index ebc60e7..ca6900a 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -75,10 +75,10 @@ impl Bibiman { // Constructs a new instance of [`App`]. pub fn new(args: CLIArgs) -> Result<Self> { let main_bibfile = args.bibfilearg; - let main_biblio = BibiSetup::new(main_bibfile.clone()); + let main_biblio = BibiSetup::new(&main_bibfile); let tag_list = TagList::new(main_biblio.keyword_list.clone()); let search_struct = BibiSearch::default(); - let entry_table = EntryTable::new(main_biblio.entry_list.clone()); + let entry_table = EntryTable::new(&main_biblio.entry_list); let current_area = CurrentArea::EntryArea; Ok(Self { main_bibfile, @@ -93,10 +93,10 @@ impl Bibiman { } pub fn update_lists(&mut self) { - self.main_biblio = BibiSetup::new(self.main_bibfile.clone()); + self.main_biblio = BibiSetup::new(&self.main_bibfile); // self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()); self.tag_list = TagList::new(self.main_biblio.keyword_list.clone()); - self.entry_table = EntryTable::new(self.main_biblio.entry_list.clone()); + self.entry_table = EntryTable::new(&self.main_biblio.entry_list); } /// Toggle moveable list between entries and tags @@ -120,7 +120,7 @@ impl Bibiman { } pub fn reset_current_list(&mut self) { - self.entry_table = EntryTable::new(self.main_biblio.entry_list.clone()); + self.entry_table = EntryTable::new(&self.main_biblio.entry_list); self.tag_list = TagList::new(self.main_biblio.keyword_list.clone()); if let CurrentArea::TagArea = self.current_area { self.tag_list.tag_list_state.select(Some(0)) @@ -282,7 +282,7 @@ impl Bibiman { let citekey = self.get_selected_citekey(); // create independent copy of citekey for finding entry after updating list let saved_key = citekey.to_owned(); - let filepath = self.main_biblio.bibfile.display().to_string(); + let filepath = self.main_bibfile.display().to_string(); let filecontent = self.main_biblio.bibfilestring.clone(); let mut line_count = 0; diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index a743856..b5dae8e 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -30,7 +30,7 @@ pub enum FileFormat { // TODO: can surely be made more efficient/simpler #[derive(Debug)] pub struct BibiSetup { - pub bibfile: PathBuf, // path to bibfile + // pub bibfile: PathBuf, // path to bibfile pub bibfile_format: FileFormat, // Format of passed file pub bibfilestring: String, // content of bibfile as string pub bibliography: Bibliography, // parsed bibliography @@ -39,7 +39,7 @@ pub struct BibiSetup { pub entry_list: Vec<BibiData>, // List of all entries } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct BibiData { pub authors: String, pub title: String, @@ -54,17 +54,16 @@ pub struct BibiData { } impl BibiSetup { - pub fn new(main_bibfile: PathBuf) -> Self { + pub fn new(main_bibfile: &PathBuf) -> Self { // TODO: Needs check for config file path as soon as config file is impl - let bibfile_format = Self::check_file_format(&main_bibfile); - let bibfile = main_bibfile; - let bibfilestring = fs::read_to_string(&bibfile).unwrap(); + let bibfile_format = Self::check_file_format(main_bibfile); + let bibfilestring = fs::read_to_string(main_bibfile).unwrap(); let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap(); let citekeys = Self::get_citekeys(&bibliography); let keyword_list = Self::collect_tag_list(&citekeys, &bibliography); let entry_list = Self::create_entry_list(&citekeys, &bibliography); Self { - bibfile, + // bibfile, bibfile_format, bibfilestring, bibliography, diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs index 7b19c38..025b696 100644 --- a/src/bibiman/entries.rs +++ b/src/bibiman/entries.rs @@ -41,7 +41,7 @@ pub struct EntryTable { } impl EntryTable { - pub fn new(entry_list: Vec<BibiData>) -> Self { + pub fn new(entry_list: &[BibiData]) -> Self { let entry_table_items = Self::set_entry_table(entry_list); let entry_table_state = TableState::default() .with_selected(0) @@ -62,21 +62,21 @@ impl EntryTable { } } - pub fn set_entry_table(entry_list: Vec<BibiData>) -> Vec<EntryTableItem> { + pub fn set_entry_table(entry_list: &[BibiData]) -> Vec<EntryTableItem> { let mut entry_table: Vec<EntryTableItem> = entry_list .into_iter() .map(|e| EntryTableItem { - authors: e.authors, + authors: e.authors.clone(), short_author: String::new(), - title: e.title, - year: e.year, - pubtype: e.pubtype, - keywords: e.keywords, - citekey: e.citekey, - abstract_text: e.abstract_text, - doi_url: e.doi_url, - filepath: e.filepath, - subtitle: e.subtitle, + title: e.title.clone(), + year: e.year.clone(), + pubtype: e.pubtype.clone(), + keywords: e.keywords.clone(), + citekey: e.citekey.clone(), + abstract_text: e.abstract_text.clone(), + doi_url: e.doi_url.clone(), + filepath: e.filepath.clone(), + subtitle: e.subtitle.clone(), }) .collect(); |
