-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves annotation delegating macro to a central location
- Loading branch information
Zack Slayton
committed
Feb 13, 2024
1 parent
aa2a29b
commit a95864d
Showing
3 changed files
with
42 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
pub mod v1_0; | ||
pub mod v1_1; | ||
|
||
/// Takes a series of `TYPE => METHOD` pairs, generating a function for each that calls the host | ||
/// type's `encode_annotated` method to encode an annotations sequence and then delegates encoding | ||
/// the value to the corresponding value writer method. | ||
// This macro is used in the v1_0 and v1_1 binary writer implementations, which both define an | ||
// `encode_annotated` method. That method is not codified (for example: in a trait); this relies | ||
// solely on convention between the two. | ||
macro_rules! annotate_and_delegate { | ||
// End of iteration | ||
() => {}; | ||
// Recurses one argument pair at a time | ||
($value_type:ty => $method:ident, $($rest:tt)*) => { | ||
fn $method(self, value: $value_type) -> IonResult<()> { | ||
self.encode_annotated(|value_writer| value_writer.$method(value)) | ||
} | ||
annotate_and_delegate!($($rest)*); | ||
}; | ||
} | ||
pub(crate) use annotate_and_delegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters