Skip to content

Commit

Permalink
Merge pull request #35 from CosmWasm/column-push-return-pk
Browse files Browse the repository at this point in the history
Return index on `Column::push`
  • Loading branch information
uint authored May 8, 2024
2 parents 43f68fa + d9c1976 commit 1a7cb1f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/storey/src/containers/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ where
/// access.push(&1337).unwrap();
/// access.push(&42).unwrap();
/// ```
pub fn push(&mut self, value: &T) -> Result<(), PushError<E::EncodeError>> {
pub fn push(&mut self, value: &T) -> Result<u32, PushError<E::EncodeError>> {
let bytes = value.encode()?;

let ix = match self
Expand All @@ -292,7 +292,7 @@ where
.unwrap_or(0);
self.storage.set_meta(META_LEN, &(len + 1).to_be_bytes());

Ok(())
Ok(ix)
}

/// Update the value associated with the given key.
Expand Down Expand Up @@ -413,8 +413,8 @@ mod tests {
let column = Column::<u64, TestEncoding>::new(0);
let mut access = column.access(&mut storage);

access.push(&1337).unwrap();
access.push(&42).unwrap();
assert_eq!(access.push(&1337).unwrap(), 0);
assert_eq!(access.push(&42).unwrap(), 1);

assert_eq!(access.get(0).unwrap(), Some(1337));
assert_eq!(access.get(1).unwrap(), Some(42));
Expand Down

0 comments on commit 1a7cb1f

Please sign in to comment.