Skip to content

Commit

Permalink
fix: return new instance on MathMl::map
Browse files Browse the repository at this point in the history
  • Loading branch information
nfejzic committed Dec 22, 2023
1 parent d9b9439 commit cc4c708
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ impl MathMl {
/// Map the content contained in [`MathMl`].
///
/// Useful, for example, when wrapping the content in [`elements::Row`] is desired.
pub fn map(&mut self, f: impl FnOnce(Elements) -> Elements) {
self.content = f(std::mem::take(&mut self.content));
///
/// # Example
/// ```ignore
/// let out = MathMl::with_content(
/// Frac::builder()
/// .num(Ident::from("x"))
/// .denom(Ident::from("y"))
/// .build(),
/// )
/// .map(Row::from)
/// .render();
/// ```
pub fn map<T>(mut self, f: impl FnOnce(Elements) -> T) -> Self
where
T: IntoElements,
{
self.content = f(self.content).into_elements();
self
}

/// Get a reference to all attributes of the `math` element.
Expand Down

0 comments on commit cc4c708

Please sign in to comment.