Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return index on Column::push #35

Merged
merged 1 commit into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading