Skip to content

Commit

Permalink
piecrust: add Session::remove_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jan 15, 2025
1 parent 17d5816 commit cbc5c84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions piecrust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add `Session::set_meta` [#rusk_3341]
- Add `Session::remove_meta` [#rusk_3341]

## [0.27.0] - 2024-12-18

Expand Down
17 changes: 17 additions & 0 deletions piecrust/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,16 @@ impl Session {
Ok(self.inner.data.set(name, data))
}

/// Remove a metadata item.
///
/// Returns the value of the removed item (if any).
pub fn remove_meta<S>(&mut self, name: S) -> Option<Vec<u8>>
where
S: Into<Cow<'static, str>>,
{
self.inner.data.remove(name)
}

pub fn serialize_data<V>(value: &V) -> Result<Vec<u8>, Error>
where
V: for<'a> Serialize<StandardBufSerializer<'a>>,
Expand Down Expand Up @@ -916,6 +926,13 @@ impl SessionData {
{
self.data.insert(name.into(), data)
}

fn remove<S>(&mut self, name: S) -> Option<Vec<u8>>
where
S: Into<Cow<'static, str>>,
{
self.data.remove(&name.into())
}
}

impl From<SessionDataBuilder> for SessionData {
Expand Down

0 comments on commit cbc5c84

Please sign in to comment.