@@ -2,7 +2,6 @@ use crate::errors::*;
22
33use std:: str:: FromStr ;
44
5-
65#[ derive( Debug , PartialEq , Clone ) ]
76pub enum EntryType {
87 Description ,
@@ -143,8 +142,7 @@ impl FromStr for Metadata {
143142 type Err = Error ;
144143
145144 fn from_str ( code : & str ) -> Result < Metadata > {
146- let ( _, lines) = metalines ( code)
147- . map_err ( |_| format_err ! ( "Failed to parse header" ) ) ?;
145+ let ( _, lines) = metalines ( code) . map_err ( |_| format_err ! ( "Failed to parse header" ) ) ?;
148146
149147 let mut data = NewMetadata :: default ( ) ;
150148
@@ -173,16 +171,20 @@ pub struct NewMetadata<'a> {
173171
174172impl < ' a > NewMetadata < ' a > {
175173 fn try_from ( self ) -> Result < Metadata > {
176- let description = self . description . ok_or_else ( || format_err ! ( "Description is required" ) ) ?;
177- let version = self . version . ok_or_else ( || format_err ! ( "Version is required" ) ) ?;
174+ let description = self
175+ . description
176+ . ok_or_else ( || format_err ! ( "Description is required" ) ) ?;
177+ let version = self
178+ . version
179+ . ok_or_else ( || format_err ! ( "Version is required" ) ) ?;
178180 let source = match self . source {
179181 Some ( x) => Some ( x. parse ( ) ?) ,
180182 _ => None ,
181183 } ;
182- let keyring_access = self . keyring_access . into_iter ( )
183- . map ( String :: from )
184- . collect ( ) ;
185- let license = self . license . ok_or_else ( || format_err ! ( "License is required" ) ) ?;
184+ let keyring_access = self . keyring_access . into_iter ( ) . map ( String :: from ) . collect ( ) ;
185+ let license = self
186+ . license
187+ . ok_or_else ( || format_err ! ( "License is required" ) ) ?;
186188 let license = license. parse ( ) ?;
187189
188190 Ok ( Metadata {
@@ -219,55 +221,71 @@ mod tests {
219221
220222 #[ test]
221223 fn verify_simple ( ) {
222- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
224+ let metadata = Metadata :: from_str (
225+ r#"-- Description: Hello world, this is my description
223226-- Version: 1.0.0
224227-- Source: domains
225228-- License: WTFPL
226229
227- "# ) . expect ( "parse" ) ;
228- assert_eq ! ( metadata, Metadata {
229- description: "Hello world, this is my description" . to_string( ) ,
230- version: "1.0.0" . to_string( ) ,
231- license: License :: WTFPL ,
232- source: Some ( Source :: Domains ) ,
233- keyring_access: Vec :: new( ) ,
234- } ) ;
230+ "# ,
231+ )
232+ . expect ( "parse" ) ;
233+ assert_eq ! (
234+ metadata,
235+ Metadata {
236+ description: "Hello world, this is my description" . to_string( ) ,
237+ version: "1.0.0" . to_string( ) ,
238+ license: License :: WTFPL ,
239+ source: Some ( Source :: Domains ) ,
240+ keyring_access: Vec :: new( ) ,
241+ }
242+ ) ;
235243 }
236244
237245 #[ test]
238246 fn verify_no_source ( ) {
239- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
247+ let metadata = Metadata :: from_str (
248+ r#"-- Description: Hello world, this is my description
240249-- Version: 1.0.0
241250-- License: WTFPL
242251
243- "# ) . expect ( "parse" ) ;
244- assert_eq ! ( metadata, Metadata {
245- description: "Hello world, this is my description" . to_string( ) ,
246- version: "1.0.0" . to_string( ) ,
247- license: License :: WTFPL ,
248- source: None ,
249- keyring_access: Vec :: new( ) ,
250- } ) ;
252+ "# ,
253+ )
254+ . expect ( "parse" ) ;
255+ assert_eq ! (
256+ metadata,
257+ Metadata {
258+ description: "Hello world, this is my description" . to_string( ) ,
259+ version: "1.0.0" . to_string( ) ,
260+ license: License :: WTFPL ,
261+ source: None ,
262+ keyring_access: Vec :: new( ) ,
263+ }
264+ ) ;
251265 }
252266
253267 #[ test]
254268 fn verify_require_license ( ) {
255- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
269+ let metadata = Metadata :: from_str (
270+ r#"-- Description: Hello world, this is my description
256271-- Version: 1.0.0
257272-- Source: domains
258273
259- "# ) ;
274+ "# ,
275+ ) ;
260276 assert ! ( metadata. is_err( ) ) ;
261277 }
262278
263279 #[ test]
264280 fn verify_require_opensource_license ( ) {
265- let metadata = Metadata :: from_str ( r#"-- Description: Hello world, this is my description
281+ let metadata = Metadata :: from_str (
282+ r#"-- Description: Hello world, this is my description
266283-- Version: 1.0.0
267284-- Source: domains
268285-- License: Proprietary
269286
270- "# ) ;
287+ "# ,
288+ ) ;
271289 assert ! ( metadata. is_err( ) ) ;
272290 }
273291
0 commit comments