Skip to content

Commit

Permalink
Merge pull request #223 from rruckley/bug-macro-hasnote-222
Browse files Browse the repository at this point in the history
Bug: Macro hasNote Trait
  • Loading branch information
rruckley authored Jan 22, 2025
2 parents f3dea1c + b6d3a10 commit 258d08d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
12 changes: 6 additions & 6 deletions tmflib-derive/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions tmflib-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]

[package]
name = "tmflib-derive"
version = "0.1.29"
version = "0.1.30"
edition = "2021"
authors = ["Ryan Ruckley <[email protected]>"]
description = "Derive macro for the tmflib::HasId trait"
Expand All @@ -11,6 +13,6 @@ repository = "https://github.com/rruckley/tmflib"
proc-macro = true

[dependencies]
proc-macro2 = "1.0.92"
proc-macro2 = "1.0.93"
quote = "1.0.38"
syn = "2.0.95"
syn = "2.0.96"
15 changes: 12 additions & 3 deletions tmflib-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,22 @@ pub fn hasnote_derive(input: TokenStream) -> TokenStream {
let out = quote! {
impl HasNote for #name {
fn add_note(&mut self, note : Note) {
self.note.as_mut().unwrap().push(note);
match self.note.as_mut() {
Some(v) => v.push(note),
None => self.note = Some(vec![note]),
}
}
fn get_note(&self, idx : usize) -> Option<&Note> {
self.note.as_ref().unwrap().get(idx)
match self.note.as_ref() {
Some(n) => n.get(idx),
None => None,
}
}
fn remove_note(&mut self, idx: usize) -> Result<Note,String> {
Ok(self.note.as_mut().unwrap().remove(idx))
match self.note.as_mut() {
Some(n) => Ok(n.remove(idx)),
None => Err(String::from("No notes present")),
}
}
}
};
Expand Down

0 comments on commit 258d08d

Please sign in to comment.