]> git.lizzy.rs Git - rust.git/blobdiff - src/text.rs
Add minimal docs to most public symbols
[rust.git] / src / text.rs
index ac1a54a7582025381f02fa4446043f0e36542eea..4084bf44e8f98fced29a1b75b45c592449bfdde4 100644 (file)
@@ -1,14 +1,17 @@
 use std::fmt;
 use std::ops;
 
+/// An text position in a source file
 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub struct TextUnit(u32);
 
 impl TextUnit {
+    /// The positional offset required for one character
     pub fn len_of_char(c: char) -> TextUnit {
         TextUnit(c.len_utf8() as u32)
     }
 
+    #[allow(missing_docs)]
     pub fn new(val: u32) -> TextUnit {
         TextUnit(val)
     }
@@ -64,6 +67,7 @@ fn sub_assign(&mut self, rhs: TextUnit) {
     }
 }
 
+/// A range of text in a source file
 #[derive(Clone, Copy, PartialEq, Eq)]
 pub struct TextRange {
     start: TextUnit,
@@ -83,10 +87,12 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl TextRange {
+    /// An length-0 range of text
     pub fn empty() -> TextRange {
         TextRange::from_to(TextUnit::new(0), TextUnit::new(0))
     }
 
+    /// The left-inclusive range (`[from..to)`) between to points in the text
     pub fn from_to(from: TextUnit, to: TextUnit) -> TextRange {
         assert!(from <= to, "Invalid text range [{}; {})", from, to);
         TextRange {
@@ -95,22 +101,27 @@ pub fn from_to(from: TextUnit, to: TextUnit) -> TextRange {
         }
     }
 
+    /// The range from some point over some length
     pub fn from_len(from: TextUnit, len: TextUnit) -> TextRange {
         TextRange::from_to(from, from + len)
     }
 
+    /// The starting position of this range
     pub fn start(&self) -> TextUnit {
         self.start
     }
 
+    /// The end position of this range
     pub fn end(&self) -> TextUnit {
         self.end
     }
 
+    /// The length of this range
     pub fn len(&self) -> TextUnit {
         self.end - self.start
     }
 
+    /// Is this range empty of any content?
     pub fn is_empty(&self) -> bool {
         self.start() == self.end()
     }