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

FromDatum overhaul #521

Closed
wants to merge 6 commits into from
Closed

FromDatum overhaul #521

wants to merge 6 commits into from

Conversation

eeeebbbbrrrr
Copy link
Contributor

This PR overhauls the FromDatum trait by making some backwards incompatible API changes.

Primarily, the changes are:

  • Remove the const NEEDS_TYPID const field. All usages of it were false
  • Remove the typid: Oid argument from the ::from_datum() function. This was never used in any meaningful way
  • Add a new ::try_from_datum(datum, is_null, type_oid) -> TryFromDatumResult<Option<Self>, TryFromDatumError) function that will return an Err if the provided type_oid isn't compatible with the desired Rust type
  • Add a new IntoDatum::is_compatible_with(type_oid) function to help facilitate the above

Going forward, these changes will be necessary to help implement #502, #499, and to also cleanup our Spi interface.

Once merged, this will definitely require a semver minor version bump.

This constant was set to false in all every `FromDatum` implementation, and simply isn't necessary.

Further changes to `FromDatum` are going to change how this idea worked in the first place.
This argument was never actually used, only passed around.  And in many cases it was set to `pg_sys::InvalidOid` anyways.
```rust
        } else if datum == 0 {
            panic!("array was flagged not null but datum is zero");
        }
```

As the function is already unsafe, there's no need for us to have a check for a case that is likely never going to happen.  Postgres may send us a null datum, but as long as we check `is_null` first, we're okay.
This function ensures the desired Rust type is compatible with the backing Postgres type of the Datum being converted.  If they're not compatible, an `Err` is returned rather than either panicking or leading to undefined behavior.

It's not actually used anywhere yet.
@eeeebbbbrrrr eeeebbbbrrrr requested a review from Hoverbear March 30, 2022 17:11
@eeeebbbbrrrr eeeebbbbrrrr marked this pull request as draft March 30, 2022 20:22
@eeeebbbbrrrr
Copy link
Contributor Author

closing this as all its changes are now part of #532...

@eeeebbbbrrrr eeeebbbbrrrr deleted the from-datum-overhaul branch June 20, 2023 17:58
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.

1 participant