Skip to content

Commit e3b5e30

Browse files
amazing!
1 parent 934a44b commit e3b5e30

File tree

9 files changed

+543
-65
lines changed

9 files changed

+543
-65
lines changed

Cargo.lock

Lines changed: 70 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
@@ -20,6 +20,7 @@
2020
#![warn(missing_debug_implementations, missing_docs)]
2121

2222
mod range;
23+
mod range_adjustment_tracker;
2324
mod size;
2425
mod traits;
2526

@@ -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+
range_adjustment_tracker::{RangeAdjustmentsTracker, RangeAdjustmentsTrackerBuilder},
36+
size::TextSize,
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)