@@ -119,40 +119,47 @@ pub fn bytes_of_file(
119119 Ok ( id)
120120}
121121
122- /// A utility to automatically generate a hash while writing into an inner writer.
123- pub struct Write < T > {
124- /// The hash implementation.
125- pub hash : Sha1 ,
126- /// The inner writer.
127- pub inner : T ,
128- }
129-
130- impl < T > std:: io:: Write for Write < T >
131- where
132- T : std:: io:: Write ,
133- {
134- fn write ( & mut self , buf : & [ u8 ] ) -> std:: io:: Result < usize > {
135- let written = self . inner . write ( buf) ?;
136- self . hash . update ( & buf[ ..written] ) ;
137- Ok ( written)
122+ #[ cfg( any( feature = "sha1" , feature = "fast-sha1" ) ) ]
123+ mod write {
124+ use crate :: hash:: Sha1 ;
125+
126+ /// A utility to automatically generate a hash while writing into an inner writer.
127+ pub struct Write < T > {
128+ /// The hash implementation.
129+ pub hash : Sha1 ,
130+ /// The inner writer.
131+ pub inner : T ,
138132 }
139133
140- fn flush ( & mut self ) -> std:: io:: Result < ( ) > {
141- self . inner . flush ( )
134+ impl < T > std:: io:: Write for Write < T >
135+ where
136+ T : std:: io:: Write ,
137+ {
138+ fn write ( & mut self , buf : & [ u8 ] ) -> std:: io:: Result < usize > {
139+ let written = self . inner . write ( buf) ?;
140+ self . hash . update ( & buf[ ..written] ) ;
141+ Ok ( written)
142+ }
143+
144+ fn flush ( & mut self ) -> std:: io:: Result < ( ) > {
145+ self . inner . flush ( )
146+ }
142147 }
143- }
144148
145- impl < T > Write < T >
146- where
147- T : std:: io:: Write ,
148- {
149- /// Create a new hash writer which hashes all bytes written to `inner` with a hash of `kind`.
150- pub fn new ( inner : T , kind : git_hash:: Kind ) -> Self {
151- match kind {
152- git_hash:: Kind :: Sha1 => Write {
153- inner,
154- hash : Sha1 :: default ( ) ,
155- } ,
149+ impl < T > Write < T >
150+ where
151+ T : std:: io:: Write ,
152+ {
153+ /// Create a new hash writer which hashes all bytes written to `inner` with a hash of `kind`.
154+ pub fn new ( inner : T , kind : git_hash:: Kind ) -> Self {
155+ match kind {
156+ git_hash:: Kind :: Sha1 => Write {
157+ inner,
158+ hash : Sha1 :: default ( ) ,
159+ } ,
160+ }
156161 }
157162 }
158163}
164+ #[ cfg( any( feature = "sha1" , feature = "fast-sha1" ) ) ]
165+ pub use write:: Write ;
0 commit comments