Skip to content

Commit 53d29fd

Browse files
committed
Add more docs
1 parent be75985 commit 53d29fd

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
## 1.0.0 :tada:
4+
5+
* the carate is renmaed to `text-size` from `text_unit`
6+
7+
Transition table:
8+
- `TextUnit::of_char(c)``TextSize::of(c)`
9+
- `TextUnit::of_str(s)``TextSize::of(s)`
10+
- `TextUnit::from_usize(size)``TextSize::try_from(size).unwrap_or_else(|| panic!(_))`
11+
- `unit.to_usize()``usize::from(size)`
12+
- `TextRange::from_to(from, to)``TextRange::new(from, to)`
13+
- `TextRange::offset_len(offset, size)``TextRange::from_len(offset, size)`
14+
- `range.start()``range.start()`
15+
- `range.end()``range.end()`
16+
- `range.len()``range.len()`
17+
- `range.is_empty()``range.is_empty()`
18+
- `a.is_subrange(b)``b.contains_range(a)`
19+
- `a.intersection(b)``a.intersect(b)`
20+
- `a.extend_to(b)``a.cover(b)`
21+
- `range.contains(offset)``range.contains(point)`
22+
- `range.contains_inclusive(offset)``range.contains_inclusive(point)`

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
//! Newtypes for working with text sizes/ranges in a more type-safe manner.
22
//!
3+
//! This library can help with two things:
4+
//! * Reducing storage requirenments for offsets and ranges, under the
5+
//! assumption that 32 bits is enough.
6+
//! * Providing standard vocabulary types for applications where text ranges
7+
//! are pervasive.
8+
//!
9+
//! However, you should not use this library simply because you work with
10+
//! strings. In the overhelming majority of cases, using `usize` and
11+
//! `std::ops::Range<usize>` is better. In particular, if you are publishing a
12+
//! library, using only std types in the interface would make it more
13+
//! interoperable. Similarly, if you are writing something like a lexer, which
14+
//! produces, but does not *store* text ranges, than sticking to `usize` would
15+
//! be better.
16+
//!
317
//! Minimal Supported Rust Version: latest stable.
418
519
#![forbid(unsafe_code)]

src/range.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@ use {
99
/// A range in text, represented as a pair of [`TextSize`][struct@TextSize].
1010
///
1111
/// It is a logic error for `start` to be greater than `end`.
12-
///
13-
/// # Translation from `text_unit`
14-
///
15-
/// - `TextRange::from_to(from, to)` ⟹ `TextRange::new(from, to)`
16-
/// - `TextRange::offset_len(offset, size)` ⟹ `TextRange::from_len(offset, size)`
17-
/// - `range.start()` ⟹ `range.start()`
18-
/// - `range.end()` ⟹ `range.end()`
19-
/// - `range.len()` ⟹ `range.len()`
20-
/// - `range.is_empty()` ⟹ `range.is_empty()`
21-
/// - `a.is_subrange(b)` ⟹ `b.contains_range(a)`
22-
/// - `a.intersection(b)` ⟹ `a.intersect(b)`
23-
/// - `a.extend_to(b)` ⟹ `a.cover(b)`
24-
/// - `range.contains(offset)` ⟹ `range.contains(point)`
25-
/// - `range.contains_inclusive(offset)` ⟹ `range.contains_inclusive(point)`
2612
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash)]
2713
pub struct TextRange {
2814
// Invariant: start <= end

src/size.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ use {
2121
///
2222
/// These escape hatches are primarily required for unit testing and when
2323
/// converting from UTF-8 size to another coordinate space, such as UTF-16.
24-
///
25-
/// # Translation from `text_unit`
26-
///
27-
/// - `TextUnit::of_char(c)` ⟹ `TextSize::of(c)`
28-
/// - `TextUnit::of_str(s)` ⟹ `TextSize::of(s)`
29-
/// - `TextUnit::from_usize(size)` ⟹ `TextSize::try_from(size).unwrap_or_else(|| panic!(_))`
30-
/// - `unit.to_usize()` ⟹ `usize::from(size)`
3124
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
3225
pub struct TextSize {
3326
pub(crate) raw: u32,

0 commit comments

Comments
 (0)