Skip to content

Add support for different sized integers#178

Merged
matthiasbeyer merged 4 commits intorust-cli:masterfrom
matthiasbeyer:integers
Nov 21, 2021
Merged

Add support for different sized integers#178
matthiasbeyer merged 4 commits intorust-cli:masterfrom
matthiasbeyer:integers

Conversation

@matthiasbeyer
Copy link
Member

This also enables support for 128 bit integers.
Nothing is tested, though.


I guess this is a draft for now.

@matthiasbeyer
Copy link
Member Author

This is related to #161 and #167

@Nukesor
Copy link

Nukesor commented Mar 17, 2021

Great to see you taking care of the project!

Cheers

@matthiasbeyer
Copy link
Member Author

Thanks ❤️

@matthiasbeyer
Copy link
Member Author

So, I guess this PR should add a bunch of tests to check

  • Are the right integer types are used
  • Do things fail properly if the size of the types in use are wrong
  • Edgecases (i8::MAX vs u8::MAX) - any maybe we can add u... support as well
  • possibly more

@matthiasbeyer
Copy link
Member Author

Hm, so after some more investigation: Our backend crates do not support integers smaller than i64. So I guess there's no point in supporting them either, is there?

@matthiasbeyer
Copy link
Member Author

@Nukesor and @nagisa - would you like to review my patchset here? There are too few tests, if you can provide some, that'd be awesome, too!

@matthiasbeyer matthiasbeyer marked this pull request as ready for review March 26, 2021 16:13
/// Returns `self` into an i128, if possible.
pub fn into_int128(self) -> Result<i128> {
match self.kind {
ValueKind::I64(value) => Ok(value as i128),
Copy link

Choose a reason for hiding this comment

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

Consider .into() instead of casting.

)),

ValueKind::String(ref s) => {
match s.to_lowercase().as_ref() {
Copy link

Choose a reason for hiding this comment

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

Why do we do this, but don't transparently allow, say, u128 values that are in range of i128 to convert to i128?

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 guess you wanted another line to be commented here? I will investigate where we can do this, yes!

Copy link

Choose a reason for hiding this comment

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

No, I meant to ask why we transparently convert strings like yes or no to integers, but not integers to other integers. Seemed somewhat counterintuitive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, now I see what you mean.

This patch tries to mimic the behavior of the non-int128 code... I agree that this might be not what we want for the next release, but I would introduce a change to that behavior in another PR, not in this one.

@nagisa
Copy link

nagisa commented Mar 26, 2021

This broadly LGTM, but I have no say over this project, really.

@matthiasbeyer
Copy link
Member Author

Still, your opinion matters to me. Thanks for the review!

@matthiasbeyer
Copy link
Member Author

Rebased on master. Still not sure whether I should merge this or not.

This also enables support for 128 bit integers.
Nothing is tested, though.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
All our backend crates do not support integers smaller than i64, so
there's no point in supporting them either.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
@matthiasbeyer
Copy link
Member Author

Updated to master, will merge if CI succeeds

epage added a commit to epage/config-rs that referenced this pull request Feb 4, 2026
This looks like something that was missed during rust-cli#178.
epage added a commit that referenced this pull request Feb 4, 2026
This looks like something that was missed during #178.
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.

3 participants