diff options
| author | lukeflo | 2025-01-29 20:42:21 +0100 |
|---|---|---|
| committer | lukeflo | 2025-01-29 20:42:21 +0100 |
| commit | fb34960e523b8f618fc4e024902f43928d8aa716 (patch) | |
| tree | 22fec98a9605360a9b5d446db63af8229785c733 /src | |
| parent | 6e320ef536e9bb1c73f583e26d5a765c3214ef83 (diff) | |
| download | bibiman-fb34960e523b8f618fc4e024902f43928d8aa716.tar.gz bibiman-fb34960e523b8f618fc4e024902f43928d8aa716.zip | |
try with borrowed values
Diffstat (limited to 'src')
| -rw-r--r-- | src/bibiman.rs | 6 | ||||
| -rw-r--r-- | src/bibiman/entries.rs | 82 |
2 files changed, 44 insertions, 44 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs index 7fd98cd..9955896 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -59,7 +59,7 @@ pub enum FormerArea { // Application. #[derive(Debug)] -pub struct Bibiman { +pub struct Bibiman<'a> { // main bib file // pub main_bibfiles: Vec<PathBuf>, // main bibliography @@ -69,7 +69,7 @@ pub struct Bibiman { // tag list pub tag_list: TagList, // table items - pub entry_table: EntryTable, + pub entry_table: EntryTable<'a>, // scroll state info buffer pub scroll_info: u16, // area @@ -80,7 +80,7 @@ pub struct Bibiman { pub popup_area: PopupArea, } -impl Bibiman { +impl Bibiman<'_> { // Constructs a new instance of [`App`]. pub fn new(args: &CLIArgs) -> Result<Self> { // let main_bibfiles = args.fileargs.clone(); diff --git a/src/bibiman/entries.rs b/src/bibiman/entries.rs index 44b8660..857b01c 100644 --- a/src/bibiman/entries.rs +++ b/src/bibiman/entries.rs @@ -30,9 +30,9 @@ pub enum EntryTableColumn { // Define list containing entries as table #[derive(Debug, PartialEq, Eq)] -pub struct EntryTable { - pub entry_table_items: Vec<EntryTableItem>, - pub entry_table_at_search_start: Vec<EntryTableItem>, +pub struct EntryTable<'a> { + pub entry_table_items: Vec<EntryTableItem<'a>>, + pub entry_table_at_search_start: Vec<EntryTableItem<'a>>, pub entry_table_selected_column: EntryTableColumn, pub entry_table_sorted_by_col: Option<EntryTableColumn>, pub entry_table_reversed_sort: bool, @@ -42,8 +42,8 @@ pub struct EntryTable { pub entry_info_scroll_state: ScrollbarState, } -impl EntryTable { - pub fn new(entry_list: &[BibiData]) -> Self { +impl<'a> EntryTable<'a> { + pub fn new(entry_list: &'a [BibiData]) -> Self { let entry_table_items = Self::set_entry_table(entry_list); let entry_table_state = TableState::default() .with_selected(0) @@ -69,17 +69,17 @@ impl EntryTable { .iter() .map(|e| EntryTableItem { id: e.id, - authors: e.authors.clone(), + authors: &e.authors, short_author: String::new(), - 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(), + 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.as_deref(), filepath: e.filepath.clone(), - subtitle: e.subtitle.clone(), + subtitle: e.subtitle.as_deref(), }) .collect(); @@ -153,22 +153,22 @@ impl EntryTable { // Define contents of each entry table row #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub struct EntryTableItem { +pub struct EntryTableItem<'a> { pub id: u32, - pub authors: String, + pub authors: &'a str, pub short_author: String, - pub title: String, - pub year: String, - pub pubtype: String, - pub keywords: String, - pub citekey: String, - pub abstract_text: String, - pub doi_url: Option<String>, + pub title: &'a str, + pub year: &'a str, + pub pubtype: &'a str, + pub keywords: &'a str, + pub citekey: &'a str, + pub abstract_text: &'a str, + pub doi_url: Option<&'a str>, pub filepath: Option<OsString>, - pub subtitle: Option<String>, + pub subtitle: Option<&'a str>, } -impl EntryTableItem { +impl<'a> EntryTableItem<'a> { // This functions decides which fields are rendered in the entry table // Fields which should be usable but not visible can be left out pub fn ref_vec(&mut self) -> Vec<&str> { @@ -255,14 +255,14 @@ mod tests { fn shorten_authors() { let mut entry: EntryTableItem = EntryTableItem { id: 1, - authors: "Miller, Schmitz, Bernard".to_string(), - short_author: "".to_string(), - title: "A title".to_string(), - year: "2000".to_string(), - pubtype: "article".to_string(), - keywords: "key1, key2".to_string(), - citekey: "miller_2000".to_string(), - abstract_text: "An abstract".to_string(), + authors: "Miller, Schmitz, Bernard", + short_author: String::new(), + title: "A title", + year: "2000", + pubtype: "article", + keywords: "key1, key2", + citekey: "miller_2000", + abstract_text: "An abstract", doi_url: None, filepath: None, subtitle: None, @@ -272,14 +272,14 @@ mod tests { let mut entry_editors: EntryTableItem = EntryTableItem { id: 2, - authors: "Miller, Schmitz, Bernard (ed.)".to_string(), - short_author: "".to_string(), - title: "A title".to_string(), - year: "2000".to_string(), - pubtype: "article".to_string(), - keywords: "key1, key2".to_string(), - citekey: "miller_2000".to_string(), - abstract_text: "An abstract".to_string(), + authors: "Miller, Schmitz, Bernard (ed.)", + short_author: String::new(), + title: "A title", + year: "2000", + pubtype: "article", + keywords: "key1, key2", + citekey: "miller_2000", + abstract_text: "An abstract", doi_url: None, filepath: None, subtitle: None, |
