Skip to content

persist key/value type metadata and add MassMap::cast#10

Merged
SF-Zhou merged 3 commits intomainfrom
dev
Nov 17, 2025
Merged

persist key/value type metadata and add MassMap::cast#10
SF-Zhou merged 3 commits intomainfrom
dev

Conversation

@SF-Zhou
Copy link
Owner

@SF-Zhou SF-Zhou commented Nov 6, 2025

No description provided.

@SF-Zhou SF-Zhou requested a review from Copilot November 6, 2025 15:35
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (75c1b3a) to head (836a12e).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #10   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          898       957   +59     
=========================================
+ Hits           898       957   +59     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds type name metadata to MassMap files and introduces an unsafe cast method for type conversion. The changes store the original key and value type names in the metadata when building or merging MassMaps, and provide a mechanism to reinterpret a MassMap with different type parameters.

  • Adds key_type and value_type string fields to MassMapMeta to store type information
  • Populates these fields using std::any::type_name during map building and merging
  • Introduces a public cast method to convert between different type parameter combinations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/meta.rs Adds key_type and value_type fields to MassMapMeta struct
src/builder.rs Populates type name fields in both build and merge methods using std::any::type_name
src/massmap.rs Adds cast method for type conversion and includes a test case demonstrating the functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
/// Constructs a massmap from a [`MassMapReader`] implementation.
///
/// The method validates the leading header (magic number, metadata offset and
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comment for MassMap::load is incomplete. The third line is truncated mid-sentence. Compare with the complete documentation on MassMapInner::load (lines 49-53) which describes what happens with errors. The documentation should be completed or the incomplete lines removed.

Suggested change
/// The method validates the leading header (magic number, metadata offset and
/// The method validates the leading header (magic number, metadata offset and
/// length) and deserializes [`MassMapMeta`]. Any IO or deserialization errors
/// are forwarded to the caller.

Copilot uses AI. Check for mistakes.
}
}

pub fn cast<K, V>(self) -> MassMap<K, V, R, H>
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cast method performs an unsafe type conversion without validating that the actual stored types match K and V. Consider validating self.meta.key_type against std::any::type_name::<K>() and self.meta.value_type against std::any::type_name::<V>() and returning a Result to prevent silent type mismatches that would cause deserialization errors later.

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +186
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() on parse() will panic if the key string cannot be parsed as a u8. This could happen with valid user input (e.g., "256" or "abc"). Use proper error handling such as parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!(\"Invalid key: {}\", e)))? instead.

Suggested change
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +186
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() on parse() will panic if the key string cannot be parsed as a u16. Use proper error handling such as parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!(\"Invalid key: {}\", e)))? instead.

Suggested change
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e)))?)
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e)))?)
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e)))?)
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e)))?)
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e)))?)

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +186
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() on parse() will panic if the key string cannot be parsed as a u32. Use proper error handling such as parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!(\"Invalid key: {}\", e)))? instead.

Suggested change
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +186
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() on parse() will panic if the key string cannot be parsed as a u64. Use proper error handling such as parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!(\"Invalid key: {}\", e)))? instead.

Suggested change
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key '{}': {}", x, e))))
.transpose()?,
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key '{}': {}", x, e))))
.transpose()?,
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key '{}': {}", x, e))))
.transpose()?,
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key '{}': {}", x, e))))
.transpose()?,
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key '{}': {}", x, e))))
.transpose()?,

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +188
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() on parse() will panic if the key string cannot be parsed as a u128. Use proper error handling such as parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!(\"Invalid key: {}\", e)))? instead.

Suggested change
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key.map(|x| x.parse().unwrap()),
args.bucket,
)?,
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
"u16" => do_query(
map.cast::<u16, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
"u32" => do_query(
map.cast::<u32, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
"u64" => do_query(
map.cast::<u64, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,
"u128" => do_query(
map.cast::<u128, _>(),
args.key
.map(|x| x.parse().map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid key: {}", e))))
.transpose()?,

Copilot uses AI. Check for mistakes.
@SF-Zhou SF-Zhou merged commit 3f4c7c1 into main Nov 17, 2025
5 checks passed
@SF-Zhou SF-Zhou deleted the dev branch November 17, 2025 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments