@@ -39,20 +39,20 @@ fn poly_mod(mut c: u64, val: u64) -> u64 {
3939 c
4040}
4141
42- /// Compute the checksum of a descriptor
43- /// Note that this function does not check if the
44- /// descriptor string is syntactically correct or not.
45- /// This only computes the checksum
42+ /// Compute the checksum of a descriptor.
43+ ///
44+ /// Note that this function does not check if the descriptor string is
45+ /// syntactically correct or not. This only computes the checksum.
4646pub fn desc_checksum ( desc : & str ) -> Result < String , Error > {
4747 let mut eng = Engine :: new ( ) ;
4848 eng. input ( desc) ?;
4949 Ok ( eng. checksum ( ) )
5050}
5151
52- /// Helper function for FromStr for various
53- /// descriptor types. Checks and verifies the checksum
54- /// if it is present and returns the descriptor string
55- /// without the checksum
52+ /// Helper function for ` FromStr` for various descriptor types.
53+ ///
54+ /// Checks and verifies the checksum if it is present and returns the descriptor
55+ /// string without the checksum.
5656pub ( super ) fn verify_checksum ( s : & str ) -> Result < & str , Error > {
5757 for ch in s. as_bytes ( ) {
5858 if * ch < 20 || * ch > 127 {
@@ -74,7 +74,7 @@ pub(super) fn verify_checksum(s: &str) -> Result<&str, Error> {
7474 Ok ( desc_str)
7575}
7676
77- /// An engine to compute a checksum from a string
77+ /// An engine to compute a checksum from a string.
7878pub struct Engine {
7979 c : u64 ,
8080 cls : u64 ,
@@ -86,10 +86,10 @@ impl Default for Engine {
8686}
8787
8888impl Engine {
89- /// Construct an engine with no input
89+ /// Constructs an engine with no input.
9090 pub fn new ( ) -> Self { Engine { c : 1 , cls : 0 , clscount : 0 } }
9191
92- /// Checksum some data
92+ /// Inputs some data into the checksum engine.
9393 ///
9494 /// If this function returns an error, the `Engine` will be left in an indeterminate
9595 /// state! It is safe to continue feeding it data but the result will not be meaningful.
@@ -115,7 +115,8 @@ impl Engine {
115115 Ok ( ( ) )
116116 }
117117
118- /// Obtain the checksum of all the data thus-far fed to the engine
118+ /// Obtains the checksum characters of all the data thus-far fed to the
119+ /// engine without allocating, to get a string use [`Self::checksum`].
119120 pub fn checksum_chars ( & mut self ) -> [ char ; 8 ] {
120121 if self . clscount > 0 {
121122 self . c = poly_mod ( self . c , self . cls ) ;
@@ -130,23 +131,23 @@ impl Engine {
130131 chars
131132 }
132133
133- /// Obtain the checksum of all the data thus-far fed to the engine
134+ /// Obtains the checksum of all the data thus-far fed to the engine.
134135 pub fn checksum ( & mut self ) -> String {
135136 String :: from_iter ( self . checksum_chars ( ) . iter ( ) . copied ( ) )
136137 }
137138}
138139
139- /// A wrapper around a `fmt::Formatter` which provides checksumming ability
140+ /// A wrapper around a `fmt::Formatter` which provides checksumming ability.
140141pub struct Formatter < ' f , ' a > {
141142 fmt : & ' f mut fmt:: Formatter < ' a > ,
142143 eng : Engine ,
143144}
144145
145146impl < ' f , ' a > Formatter < ' f , ' a > {
146- /// Contruct a new `Formatter`, wrapping a given `fmt::Formatter`
147+ /// Contructs a new `Formatter`, wrapping a given `fmt::Formatter`.
147148 pub fn new ( f : & ' f mut fmt:: Formatter < ' a > ) -> Self { Formatter { fmt : f, eng : Engine :: new ( ) } }
148149
149- /// Writes the checksum into the underlying `fmt::Formatter`
150+ /// Writes the checksum into the underlying `fmt::Formatter`.
150151 pub fn write_checksum ( & mut self ) -> fmt:: Result {
151152 use fmt:: Write ;
152153 self . fmt . write_char ( '#' ) ?;
@@ -156,7 +157,7 @@ impl<'f, 'a> Formatter<'f, 'a> {
156157 Ok ( ( ) )
157158 }
158159
159- /// Writes the checksum into the underlying `fmt::Formatter`, unless it has "alternate" display on
160+ /// Writes the checksum into the underlying `fmt::Formatter`, unless it has "alternate" display on.
160161 pub fn write_checksum_if_not_alt ( & mut self ) -> fmt:: Result {
161162 if !self . fmt . alternate ( ) {
162163 self . write_checksum ( ) ?;
0 commit comments