[refurb] Count codepoints not bytes for slice-to-remove-prefix-or-suffix (FURB188) (#13631)

This commit is contained in:
Dylan 2024-10-07 09:13:28 -05:00 committed by GitHub
parent 27ac34d683
commit 14ee5dbfde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 114 additions and 7 deletions

View file

@ -96,6 +96,14 @@ impl Int {
}
}
/// Return the [`Int`] as an u64, if it can be represented as that data type.
pub fn as_usize(&self) -> Option<usize> {
match &self.0 {
Number::Small(small) => usize::try_from(*small).ok(),
Number::Big(_) => None,
}
}
/// Return the [`Int`] as an i8, if it can be represented as that data type.
pub fn as_i8(&self) -> Option<i8> {
match &self.0 {