Skip to content

Commit fcd4720

Browse files
feat(typecheck): also replace longer type defaults (#541)
1 parent f61d5a1 commit fcd4720

File tree

9 files changed

+538
-79
lines changed

9 files changed

+538
-79
lines changed

Cargo.lock

Lines changed: 69 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgt_text_size/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
mod range;
2323
mod size;
24+
mod text_range_replacement;
2425
mod traits;
2526

2627
#[cfg(feature = "serde")]
@@ -29,7 +30,12 @@ mod serde_impls;
2930
#[cfg(feature = "schema")]
3031
mod schemars_impls;
3132

32-
pub use crate::{range::TextRange, size::TextSize, traits::TextLen};
33+
pub use crate::{
34+
range::TextRange,
35+
size::TextSize,
36+
text_range_replacement::{TextRangeReplacement, TextRangeReplacementBuilder},
37+
traits::TextLen,
38+
};
3339

3440
#[cfg(target_pointer_width = "16")]
3541
compile_error!("text-size assumes usize >= u32 and does not work on 16-bit targets");

crates/pgt_text_size/src/range.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::num::TryFromIntError;
2+
13
use cmp::Ordering;
24

35
use {
@@ -443,6 +445,28 @@ where
443445
}
444446
}
445447

448+
impl TryFrom<&Range<usize>> for TextRange {
449+
type Error = TryFromIntError;
450+
451+
fn try_from(value: &Range<usize>) -> Result<Self, Self::Error> {
452+
let start: TextSize = value.start.try_into()?;
453+
let end: TextSize = value.end.try_into()?;
454+
455+
Ok(TextRange { start, end })
456+
}
457+
}
458+
459+
impl TryFrom<Range<usize>> for TextRange {
460+
type Error = TryFromIntError;
461+
462+
fn try_from(value: Range<usize>) -> Result<Self, Self::Error> {
463+
let start: TextSize = value.start.try_into()?;
464+
let end: TextSize = value.end.try_into()?;
465+
466+
Ok(TextRange { start, end })
467+
}
468+
}
469+
446470
macro_rules! ops {
447471
(impl $Op:ident for TextRange by fn $f:ident = $op:tt) => {
448472
impl $Op<&TextSize> for TextRange {

0 commit comments

Comments
 (0)