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

feat(header): Implement find method on headers #350

Merged
merged 6 commits into from
Apr 9, 2024

Conversation

nikhars
Copy link
Member

@nikhars nikhars commented Apr 5, 2024

Add the ability in the Headers struct of types to be able to find a key and if found return the corresponding value.

Add the ability in the Headers struct of types to be able to find
a key and if found return the corresponding value.
@nikhars nikhars requested review from a team as code owners April 5, 2024 23:58
@nikhars nikhars requested a review from a team April 5, 2024 23:58
rust-arroyo/src/backends/kafka/types.rs Outdated Show resolved Hide resolved
rust-arroyo/src/backends/kafka/types.rs Outdated Show resolved Hide resolved
Comment on lines 162 to 163
assert_eq!(headers.get("key1"), Some(b"value1".to_vec()).as_deref());
assert_eq!(headers.get("key2"), Some(b"value2".to_vec()).as_deref());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert_eq!(headers.get("key1"), Some(b"value1".to_vec()).as_deref());
assert_eq!(headers.get("key2"), Some(b"value2".to_vec()).as_deref());
assert_eq!(headers.get("key1"), Some(b"value1"));
assert_eq!(headers.get("key2"), Some(b"value2"));

Copy link
Member Author

Choose a reason for hiding this comment

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

The suggested change gives the following error
error[E0308]: mismatched types
--> rust-arroyo/src/backends/kafka/types.rs:162:41
|
162 | assert_eq!(headers.get("key1"), Some(b"value1"));
| ^^^^^^^^^^^^^^^ expected Option<&[u8]>, found Option<&[u8; 6]>
|
= note: expected enum Option<&[u8]>
found enum Option<&[u8; 6]>

error[E0308]: mismatched types
--> rust-arroyo/src/backends/kafka/types.rs:163:41
|
163 | assert_eq!(headers.get("key2"), Some(b"value2"));
| ^^^^^^^^^^^^^^^ expected Option<&[u8]>, found Option<&[u8; 6]>
|
= note: expected enum Option<&[u8]>
found enum Option<&[u8; 6]>

Didn't know rust would be so restrictive. Made a change to map the value and return its ref.

@nikhars nikhars merged commit 5d67ae2 into main Apr 9, 2024
11 checks passed
@nikhars nikhars deleted the nikhars/feat/kafka-header-find branch April 9, 2024 17:31
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.

2 participants