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

journal: add support for match filters #17

Merged
merged 2 commits into from
Aug 21, 2016

Conversation

lucab
Copy link
Contributor

@lucab lucab commented Aug 10, 2016

This commit introduces support for filtering journal entries.
To filter results while iterating a Journal, it is now possible
to add filtering terms, AND/OR-ing them in predicates as well as
resetting back to an unfiltered iterator.


/// Adds a match by which to filter the entries of the journal.
/// If a match is applied, only entries with this field set will be iterated.
pub fn match_add<T: Into<Vec<u8>>>(&self, key: &str, val: T) -> Result<&Journal> {
Copy link
Owner

Choose a reason for hiding this comment

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

I could use an explanation on why &mut self isn't needed here: it appears that these filtering functions are mutating internal state of the journal object.

As we're an ffi interface, it's true that we don't need to exactly follow the & and &mut meanings as provided in rust (I believe C's abi allows us a bit more leeway), but it seems like it'd be useful in this case to make it clear that the journal's internal state is being modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand the concern. This is somehow similar to other rust types providing interior mutability, minus the explicit borrowing part. And this is something that doesn't concern only this new match subsystem: seek and next_record also alters internal cursor position.

I think that conveying this semantic via comment is neither efficient nor idiomatic. What about moving to explicit &mut self, even if not strictly required by rust, to let the caller be aware of this?

Copy link
Owner

Choose a reason for hiding this comment

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

That seems fine to me (and we probably should at some point adjust the existing methods to do the same).

@lucab lucab force-pushed the to-upstream/journal-matches branch 2 times, most recently from 40de04d to 66f3e4e Compare August 19, 2016 07:46
@lucab
Copy link
Contributor Author

lucab commented Aug 19, 2016

@jmesmon as discussed, I've moved the new methods to take &mut self and piled another commit on top of this to also align existing functions. Can you please have another pass on this?

@codyps
Copy link
Owner

codyps commented Aug 19, 2016

On the returns for most of these functions, it looks like a Result<&Journal> is used I presume this is to allow chaining calls together. In that case, wouldn't it now need to be Result<&mut Journal> for chaining to take place now that &mut self is used?

lucab added 2 commits August 20, 2016 08:32
This commit introduces support for filtering journal entries.
To filter results while iterating a Journal, it is now possible
to add filtering terms, AND/OR-ing them in predicates as well as
resetting back to an unfiltered iterator.
This commit changes some methods signature to take mutable references
wherever the FFI implies some internal status mutation by the C API.
While this is not stricly needed by Rust rules, it helps in explicitly
conveying the semantic across the layers.
@lucab lucab force-pushed the to-upstream/journal-matches branch from 66f3e4e to 84cc2ee Compare August 20, 2016 08:33
@lucab
Copy link
Contributor Author

lucab commented Aug 20, 2016

You are right. The rationale behind the arbitrary return type was to make chaining easier (once safe navigation RFC is implemented), but I forgot to change it when updating. I amended it now, and also added a (superfluous) flush+match_add chain in the test just to cover that part. PTAL.

@codyps codyps merged commit 28bcd7e into codyps:master Aug 21, 2016
@codyps
Copy link
Owner

codyps commented Aug 21, 2016

Looks good, merged. Thanks.

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