33//! Currently, it pretty much exposes the internals of the CLI 1:1, but in the future
44//! this is supposed to evolve into a more standalone library.
55
6- use anyhow:: Result ;
76use diff:: { Diff , OptionExt } ;
87use nix_compat:: nixhash:: NixHash ;
98use reqwest:: IntoUrl ;
@@ -21,7 +20,7 @@ pub mod pypi;
2120pub mod tarball;
2221pub mod versions;
2322
24- pub const DEFAULT_NIX : & ' static str = include_str ! ( "default.nix" ) ;
23+ pub const DEFAULT_NIX : & str = include_str ! ( "default.nix" ) ;
2524
2625/// Helper method to build you a client.
2726// TODO make injectable via a configuration mechanism
@@ -129,10 +128,10 @@ pub trait Updatable:
129128 /// Fetch the latest applicable commit data
130129 ///
131130 /// The old version may be passed to help guarantee monotonicity of the versions.
132- async fn update ( & self , old : Option < & Self :: Version > ) -> Result < Self :: Version > ;
131+ async fn update ( & self , old : Option < & Self :: Version > ) -> anyhow :: Result < Self :: Version > ;
133132
134133 /// Fetch hashes for a given version
135- async fn fetch ( & self , version : & Self :: Version ) -> Result < Self :: Hashes > ;
134+ async fn fetch ( & self , version : & Self :: Version ) -> anyhow :: Result < Self :: Hashes > ;
136135}
137136
138137/// Create the `Pin` type
@@ -178,7 +177,7 @@ macro_rules! mkPin {
178177 } ) *
179178
180179 /* If an error is returned, `self` remains unchanged */
181- pub async fn update( & mut self ) -> Result <Vec <diff:: DiffEntry >> {
180+ pub async fn update( & mut self ) -> :: anyhow :: Result <Vec <diff:: DiffEntry >> {
182181 Ok ( match self {
183182 $( Self :: $name { input, version, .. } => {
184183 /* Use very explicit syntax to force the correct types and get good compile errors */
@@ -191,7 +190,7 @@ macro_rules! mkPin {
191190 /* If an error is returned, `self` remains unchanged. This returns a double result: the outer one
192191 * indicates that `update` should be called first, the inner is from the actual operation.
193192 */
194- pub async fn fetch( & mut self ) -> Result <Vec <diff:: DiffEntry >> {
193+ pub async fn fetch( & mut self ) -> :: anyhow :: Result <Vec <diff:: DiffEntry >> {
195194 Ok ( match self {
196195 $( Self :: $name { input, version, hashes, .. } => {
197196 let version = version. as_ref( )
@@ -225,14 +224,14 @@ macro_rules! mkPin {
225224 /// Unfreeze a pin
226225 pub fn unfreeze( & mut self ) {
227226 match self {
228- $( Self :: $name { ref mut frozen, .. } => frozen. unfreeze( ) ) ,*
227+ $( Self :: $name { frozen, .. } => frozen. unfreeze( ) ) ,*
229228 }
230229 }
231230
232231 /// Freeze a pin
233232 pub fn freeze( & mut self ) {
234233 match self {
235- $( Self :: $name { ref mut frozen, .. } => frozen. freeze( ) ) ,*
234+ $( Self :: $name { frozen, .. } => frozen. freeze( ) ) ,*
236235 }
237236 }
238237
@@ -314,7 +313,7 @@ impl NixPins {
314313 }
315314
316315 /// Custom manual deserialize wrapper that checks the version
317- pub fn from_json_versioned ( value : serde_json:: Value ) -> Result < Self > {
316+ pub fn from_json_versioned ( value : serde_json:: Value ) -> anyhow :: Result < Self > {
318317 versions:: from_value_versioned ( value)
319318 }
320319
@@ -350,7 +349,7 @@ impl diff::Diff for GenericHash {
350349}
351350
352351/// The Frozen field in a Pin
353- #[ derive( Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
352+ #[ derive( Debug , Default , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
354353pub struct Frozen ( pub bool ) ;
355354
356355impl Frozen {
@@ -377,12 +376,6 @@ impl diff::Diff for Frozen {
377376 }
378377}
379378
380- impl std:: default:: Default for Frozen {
381- fn default ( ) -> Self {
382- Frozen ( false )
383- }
384- }
385-
386379/// An URL and its hash
387380#[ derive( Debug , Serialize , Deserialize , Clone , PartialEq , Eq ) ]
388381pub struct GenericUrlHashes {
@@ -404,6 +397,7 @@ mod tests {
404397 use super :: * ;
405398
406399 #[ test]
400+ #[ rustfmt:: skip]
407401 fn test_frozen ( ) {
408402 assert ! ( !Frozen :: default ( ) . is_frozen( ) ) ;
409403 assert ! ( !{
0 commit comments