Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ToSql / FromSql for IpInet and IpCidr from cidr crate#877

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sfackler merged 3 commits intorust-postgres:masterfromtimando:cidr
Mar 17, 2022

Conversation

timando
Copy link
Contributor

No description provided.

fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let inet = types::inet_from_sql(raw)?;
Ok(IpCidr::new(inet.addr(), inet.netmask())
.expect("postgres cidr type has zeroed host portion"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why panic here instead of returning an error?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

the type only accepts postgrescidr type which postgres guarantees to be a validcidr (i.e. mask length within the limits for the address type and zeroed host portion) which is the same as the requirements to create anIpCidr.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you assume the value passed to from_sql is always correct, then there's no need for any of these implementations to return an error. The library should not assume that the input is valid.

fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<dyn Error + Sync + Send>> {
let inet = types::inet_from_sql(raw)?;
Ok(IpInet::new(inet.addr(), inet.netmask())
.expect("postgres enforces maximum length of netmask"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Similar, postgres guarantees that theinet type has a mask length corresponding to the address type (<= 32 for IPv4, <=128 for IPv6)

@sfacklersfackler merged commita638ada intorust-postgres:masterMar 17, 2022
@sfackler
Copy link
Collaborator

Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sfacklersfacklersfackler left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@timando@sfackler

[8]ページ先頭

©2009-2025 Movatter.jp