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

Add #[derive(Clone, Copy... on all bitflags #1396

Merged
merged 3 commits into from Dec 24, 2023

Conversation

nyurik
Copy link
Contributor

@nyurik nyurik commented Oct 6, 2023

This will make it easier to use them, e.g. I won't need to re-create FunctionFlags for registering multiple similar functions.

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fc738f3) 81.08% compared to head (4e0b446) 81.08%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1396   +/-   ##
=======================================
  Coverage   81.08%   81.08%           
=======================================
  Files          51       51           
  Lines       10345    10345           
=======================================
  Hits         8388     8388           
  Misses       1957     1957           

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

@gwenn
Copy link
Collaborator

gwenn commented Oct 7, 2023

Eq and PartialEq seem useless

@nyurik
Copy link
Contributor Author

nyurik commented Oct 7, 2023

They are clearly not as useful as Copy, agree, but I am sure there could be usecases where users will want to pass them around and compare them, wouldn't they? Also, there could be some implementers that wrap your library, and they might need to take extra actions before passing bitfield into the inner lib. But this is up to you - my main req is to copy bitfields to pass them around more easily (e.g. have a global const/static, etc).

Speaking of derive - there are many enums that also do not implement Copy, e.g. types::Type should be both Copy and Hash (someone may want to have a lookup for type -> value conversion of sorts?). Do you have any overall rule of thumb of what gets which derives? Thx!

@gwenn
Copy link
Collaborator

gwenn commented Oct 7, 2023

I am sure there could be usecases where ...

YAGNI: https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it

@nyurik
Copy link
Contributor Author

nyurik commented Oct 7, 2023

@gwenn YAGNII is my fav principle too, but the cost of submitting a PR and discussing it, and waiting for release is also pretty high, so what's the middle ground? I will add the clone/copy where makes sense - that's what I do need. Is that ok?

@gwenn
Copy link
Collaborator

gwenn commented Oct 7, 2023

I will add the clone/copy where makes sense - that's what I do need. Is that ok?

Yes, please.

@nyurik
Copy link
Contributor Author

nyurik commented Oct 7, 2023

i tried to clean them up a bit, adding just the copy/clone where it seem to make sense. Overall, looking at many pub enum cases, it seems the derives are very unorganized/ad-hoc, without much consistency. I will try to tame my OCD though :)

This will make it easier to use them, e.g. I won't need to re-create `FunctionFlags` for registering multiple similar functions.
@nyurik
Copy link
Contributor Author

nyurik commented Dec 17, 2023

@gwenn should i make any changes to this PR?

src/vtab/mod.rs Outdated
@@ -322,7 +323,7 @@ pub trait UpdateVTab<'vtab>: CreateVTab<'vtab> {

/// Index constraint operator.
/// See [Virtual Table Constraint Operator Codes](https://sqlite.org/c3ref/c_index_constraint_eq.html) for details.
#[derive(Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Created only by SQLite itself (readonly on rusqlite side)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

src/vtab/mod.rs Outdated
@@ -59,6 +59,7 @@ use crate::{str_to_cstring, Connection, Error, InnerConnection, Result};
// ffi::sqlite3_vtab_cursor => VTabCursor

/// Virtual table kind
#[derive(Copy, Clone, Debug)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Used only as a constant at compile time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

@@ -28,7 +28,7 @@ const SERIES_COLUMN_STOP: c_int = 2;
const SERIES_COLUMN_STEP: c_int = 3;

bitflags::bitflags! {
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use only to pass information between best_index and filter methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

src/session.rs Outdated
@@ -655,7 +655,7 @@ impl Connection {
/// See [here](https://sqlite.org/session.html#SQLITE_CHANGESET_CONFLICT) for details.
#[allow(missing_docs)]
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Created only by SQLite (readonly on rusqlite side)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

Copy link
Contributor Author

@nyurik nyurik left a comment

Choose a reason for hiding this comment

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

thx, reverted the ones you suggested, and also merged main for ease of review. You may want to squash when merging though

src/vtab/mod.rs Outdated
@@ -322,7 +323,7 @@ pub trait UpdateVTab<'vtab>: CreateVTab<'vtab> {

/// Index constraint operator.
/// See [Virtual Table Constraint Operator Codes](https://sqlite.org/c3ref/c_index_constraint_eq.html) for details.
#[derive(Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

src/vtab/mod.rs Outdated
@@ -59,6 +59,7 @@ use crate::{str_to_cstring, Connection, Error, InnerConnection, Result};
// ffi::sqlite3_vtab_cursor => VTabCursor

/// Virtual table kind
#[derive(Copy, Clone, Debug)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

src/session.rs Outdated
@@ -655,7 +655,7 @@ impl Connection {
/// See [here](https://sqlite.org/session.html#SQLITE_CHANGESET_CONFLICT) for details.
#[allow(missing_docs)]
#[repr(i32)]
#[derive(Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

@@ -28,7 +28,7 @@ const SERIES_COLUMN_STOP: c_int = 2;
const SERIES_COLUMN_STEP: c_int = 3;

bitflags::bitflags! {
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted

@gwenn gwenn merged commit 68c3083 into rusqlite:master Dec 24, 2023
16 checks passed
@nyurik nyurik deleted the impl-bit-traits branch December 24, 2023 08:37
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.

None yet

2 participants