Skip to content

Conversation

Swatinem
Copy link
Member

@Swatinem Swatinem commented Jan 3, 2022

Parsing of headers and rate limits was implemented, but filtered the
envelope was not so far.

Parsing of headers and rate limits was implemented, but filtered the
envelope was not so far.
@Swatinem Swatinem requested a review from a team January 3, 2022 13:09
Copy link
Contributor

@relaxolotl relaxolotl left a comment

Choose a reason for hiding this comment

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

left a few comments, mostly nitpicky but this otherwise looks good 👍


/// The Category of payload that a Rate Limit refers to.
#[non_exhaustive]
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

nice 🎉 would be neat if we could figure out a way to remove non_exhaustive too

Copy link
Member Author

Choose a reason for hiding this comment

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

We wouldn’t want that. Right now this is completely private, but once we make it public, we would want to have the freedom to add more categories later on.
Also the compiler is smart enough to exhaustively match inside the crate that defines the #[non_exhaustive] enum.

Comment on lines +162 to +164
// filter again, removing attachments which do not make any sense without
// an event/transaction
if filtered.uuid().is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

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

mostly nitpicky comment as this does work: it's a little unfortunate that this is the best way to determine whether an envelope contains a transaction or an event. it relies on a detail noted in the spec, but i think the envelope api could be improved to make this line a little better (and not require a comment).

i think in the future, particularly when transactions are added in a more self-descriptive check would look like self.event().is_some() || self.transaction().is_some(). there's already a getter for an event in an envelope; adding one in for a transaction seems natural once performance monitoring is added to the sdk, which would then allow us to use this predicate instead of checking the uuid.

/// empty.
pub fn filter<P>(self, mut predicate: P) -> Option<Self>
where
P: FnMut(&EnvelopeItem) -> bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

why FnMut over Fn? it doesn't look like self nor the EnvelopeItem are being mutated. filter itself appears to re-construct the envelope. does the predicate also need mut? it looks like this might be leftovers of an attempt at an implementation that mutates and filters the envelope items out of the original envelope.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not about us being mutable, rather that it makes the callback as flexible as possible, so it can possibly mutate its environment if it so choses.
I think the idea is to prefer FnOnce > FnMut > Fn if possible. For example if we save the callback on the struct, and need access to it inside a &self method, we can only go as far as Fn.

@Swatinem Swatinem merged commit 04515ba into master Jan 4, 2022
@Swatinem Swatinem deleted the feat/rlcat branch January 4, 2022 09:45
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