@@ -2,7 +2,6 @@ use crate::errors::*;
22
33use std:: str:: FromStr ;
44
5-
65#[ derive( Debug , PartialEq , Clone ) ]
76pub enum EntryType {
87 Description ,
@@ -140,8 +139,7 @@ impl FromStr for Metadata {
140139 type Err = Error ;
141140
142141 fn from_str ( code : & str ) -> Result < Metadata > {
143- let ( _, lines) = metalines ( code)
144- . map_err ( |_| format_err ! ( "Failed to parse header" ) ) ?;
142+ let ( _, lines) = metalines ( code) . map_err ( |_| format_err ! ( "Failed to parse header" ) ) ?;
145143
146144 let mut data = NewMetadata :: default ( ) ;
147145
@@ -170,16 +168,20 @@ pub struct NewMetadata<'a> {
170168
171169impl < ' a > NewMetadata < ' a > {
172170 fn try_from ( self ) -> Result < Metadata > {
173- let description = self . description . ok_or_else ( || format_err ! ( "Description is required" ) ) ?;
174- let version = self . version . ok_or_else ( || format_err ! ( "Version is required" ) ) ?;
171+ let description = self
172+ . description
173+ . ok_or_else ( || format_err ! ( "Description is required" ) ) ?;
174+ let version = self
175+ . version
176+ . ok_or_else ( || format_err ! ( "Version is required" ) ) ?;
175177 let source = match self . source {
176178 Some ( x) => Some ( x. parse ( ) ?) ,
177179 _ => None ,
178180 } ;
179- let keyring_access = self . keyring_access . into_iter ( )
180- . map ( String :: from )
181- . collect ( ) ;
182- let license = self . license . ok_or_else ( || format_err ! ( "License is required" ) ) ?;
181+ let keyring_access = self . keyring_access . into_iter ( ) . map ( String :: from ) . collect ( ) ;
182+ let license = self
183+ . license
184+ . ok_or_else ( || format_err ! ( "License is required" ) ) ?;
183185 let license = license. parse ( ) ?;
184186
185187 Ok ( Metadata {
@@ -216,55 +218,71 @@ mod tests {
216218
217219 #[ test]
218220 fn verify_simple ( ) {
219- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
221+ let metadata = Metadata :: from_str (
222+ r#"-- Description: Hello world, this is my description
220223-- Version: 1.0.0
221224-- Source: domains
222225-- License: WTFPL
223226
224- "# ) . expect ( "parse" ) ;
225- assert_eq ! ( metadata, Metadata {
226- description: "Hello world, this is my description" . to_string( ) ,
227- version: "1.0.0" . to_string( ) ,
228- license: License :: WTFPL ,
229- source: Some ( Source :: Domains ) ,
230- keyring_access: Vec :: new( ) ,
231- } ) ;
227+ "# ,
228+ )
229+ . expect ( "parse" ) ;
230+ assert_eq ! (
231+ metadata,
232+ Metadata {
233+ description: "Hello world, this is my description" . to_string( ) ,
234+ version: "1.0.0" . to_string( ) ,
235+ license: License :: WTFPL ,
236+ source: Some ( Source :: Domains ) ,
237+ keyring_access: Vec :: new( ) ,
238+ }
239+ ) ;
232240 }
233241
234242 #[ test]
235243 fn verify_no_source ( ) {
236- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
244+ let metadata = Metadata :: from_str (
245+ r#"-- Description: Hello world, this is my description
237246-- Version: 1.0.0
238247-- License: WTFPL
239248
240- "# ) . expect ( "parse" ) ;
241- assert_eq ! ( metadata, Metadata {
242- description: "Hello world, this is my description" . to_string( ) ,
243- version: "1.0.0" . to_string( ) ,
244- license: License :: WTFPL ,
245- source: None ,
246- keyring_access: Vec :: new( ) ,
247- } ) ;
249+ "# ,
250+ )
251+ . expect ( "parse" ) ;
252+ assert_eq ! (
253+ metadata,
254+ Metadata {
255+ description: "Hello world, this is my description" . to_string( ) ,
256+ version: "1.0.0" . to_string( ) ,
257+ license: License :: WTFPL ,
258+ source: None ,
259+ keyring_access: Vec :: new( ) ,
260+ }
261+ ) ;
248262 }
249263
250264 #[ test]
251265 fn verify_require_license ( ) {
252- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
266+ let metadata = Metadata :: from_str (
267+ r#"-- Description: Hello world, this is my description
253268-- Version: 1.0.0
254269-- Source: domains
255270
256- "# ) ;
271+ "# ,
272+ ) ;
257273 assert ! ( metadata. is_err( ) ) ;
258274 }
259275
260276 #[ test]
261277 fn verify_require_opensource_license ( ) {
262- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
278+ let metadata = Metadata :: from_str (
279+ r#"-- Description: Hello world, this is my description
263280-- Version: 1.0.0
264281-- Source: domains
265282-- License: Proprietary
266283
267- "# ) ;
284+ "# ,
285+ ) ;
268286 assert ! ( metadata. is_err( ) ) ;
269287 }
270288
0 commit comments