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: emit metrics for any failed notif conversions #39

Merged
merged 2 commits into from
Jul 20, 2018
Merged

Conversation

pjenvey
Copy link
Member

@pjenvey pjenvey commented Jul 20, 2018

a separate refactor commit

Closes #33

@@ -66,19 +68,22 @@ pub fn fetch_messages(
..Default::default()
};

let metrics = Rc::clone(metrics);
Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed the rust team began recommending Rc::clone vs .clone about a year ago, makes it clearer that this is a cheap Rc clone vs worrying about it being a different clone

Copy link
Member

Choose a reason for hiding this comment

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

It makes sense for containers like RC (and I suppose vec may be similar), but I keep feeling that a given object should be responsible for making it's own clone, since it knows best how deep it needs to copy itself. I wonder if we'll see this pattern play out for other, similar structures?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not Vec but it makes sense for smart pointers. the original RFC (which suggested a new method new_ref instead that was rejected) mentioned Rc/Arc and the associated Weak pointer types. Here's a pretty good example it outlines:

https://github.com/nical/rfcs/blob/rc-newref-clone/text/0000-rc-newref-clone.md#example

where
E: Display,
{
error!("Failed {} conversion: {}", name, err);
Copy link
Member Author

Choose a reason for hiding this comment

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

I had this as debug! but figured let's error! for now so it's seen on prod

Copy link
Member

Choose a reason for hiding this comment

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

👍


/// Like Result::ok, convert from Result<T, E> to Option<T> but applying a
/// function to the Err value
fn ok_or_inspect<T, E, F>(result: StdResult<T, E>, op: F) -> Option<T>
Copy link
Member Author

Choose a reason for hiding this comment

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

almost tempted to make this into a whole trait extension, time will tell how useful it is

Copy link
Member

Choose a reason for hiding this comment

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

Well, right now you're using it just to contain a call to conversion_err. (I almost wonder if it might just be better to combine them into one call to reduce some of the templating, but that's a super minor nit.)

It'll be interesting to see how these play out in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had it that way to start with then ended up here. Already had in mind I wanted an Option::ok_or_else like call for Result (but it doesn't have one because it would be dropping Err in that case).

It had "ua.notification_read.error" either embedded inside of it or that also needed to be an argument, so went for the generic combinator I really wanted

@pjenvey pjenvey force-pushed the feat/33 branch 3 times, most recently from ed16b64 to 7ef1594 Compare July 20, 2018 17:15
bbangert
bbangert previously approved these changes Jul 20, 2018

/// Like Result::ok, convert from Result<T, E> to Option<T> but applying a
/// function to the Err value
fn ok_or_inspect<T, E, F>(result: StdResult<T, E>, op: F) -> Option<T>
Copy link
Member

Choose a reason for hiding this comment

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

Well, right now you're using it just to contain a call to conversion_err. (I almost wonder if it might just be better to combine them into one call to reduce some of the templating, but that's a super minor nit.)

It'll be interesting to see how these play out in the future.

@jrconlin jrconlin merged commit d42a21b into master Jul 20, 2018
@bbangert bbangert deleted the feat/33 branch July 20, 2018 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants