@@ -3,30 +3,30 @@ SPDX-License-Identifier: MPL-2.0
33SPDX-FileCopyrightText: © 2023 Bruce D'Arcus
44*/
55
6- //! A reference is a bibliographic item, such as a book, article, or web page.
6+ //! A reference is a bibliographic item, such as a book, article, or web page.
77//! It is the basic unit of bibliographic data.
8- //!
9- //! The model includes the following core data types.
8+ //!
9+ //! The model includes the following core data types.
1010//! Each is designed to be as simple as possible, while also allowing more complex data structures.
11- //!
11+ //!
1212//! ## Title
13- //!
13+ //!
1414//! A title can be a single string, a structured title, or a multilingual title.
15- //!
15+ //!
1616//! ## Contributor
17- //!
17+ //!
1818//! A contributor can be a single string, a structured name, or a list of contributors.
19- //!
19+ //!
2020//! ## Date
21- //!
22- //! Dates can either be EDTF strings, for flexible dates and date-times, or literal strings.
21+ //!
22+ //! Dates can either be EDTF strings, for flexible dates and date-times, or literal strings.
2323//! Literal strings can be used for examples like "Han Dynasty".
2424
2525use edtf:: level_1:: Edtf ;
2626use schemars:: JsonSchema ;
2727use serde:: { Deserialize , Serialize } ;
2828use std:: fmt;
29- use style:: { locale:: MonthList , options:: StyleOptions } ;
29+ use style:: { locale:: MonthList , options:: Config } ;
3030use url:: Url ;
3131//use icu::calendar::DateTime;
3232
@@ -347,24 +347,25 @@ impl fmt::Display for ContributorList {
347347
348348/// A Name is a string that can be formatted in different ways.
349349pub trait Name {
350- fn names ( & self , options : StyleOptions , as_sorted : bool ) -> String ;
350+ fn names ( & self , options : Config , as_sorted : bool ) -> String ;
351351}
352352
353353/// A NameList is a list of names that can be formatted in different ways, depending on configuration options, and context.
354354pub trait NameList {
355355 /// Return a list of names, formatted according to the given options.
356356 /// If `as_sorted` is true, the names will be displayed as sorted.
357- fn names_list ( & self , options : StyleOptions , as_sorted : bool ) -> String ;
357+ fn names_list ( & self , options : Config , as_sorted : bool ) -> String ;
358358}
359359
360360impl Name for Contributor {
361361 // if as_sorted is true, the name will be displayed as sorted.
362- fn names ( & self , options : StyleOptions , as_sorted : bool ) -> String {
363- let as_sorted_config = match options. contributors . display_as_sort {
364- style:: options:: DisplayAsSort :: All => true ,
365- style:: options:: DisplayAsSort :: First => true ,
366- style:: options:: DisplayAsSort :: None => false ,
367- } ;
362+ fn names ( & self , options : Config , as_sorted : bool ) -> String {
363+ let as_sorted_config =
364+ match options. contributors . clone ( ) . unwrap_or_default ( ) . display_as_sort {
365+ style:: options:: DisplayAsSort :: All => true ,
366+ style:: options:: DisplayAsSort :: First => true ,
367+ style:: options:: DisplayAsSort :: None => false ,
368+ } ;
368369 match self {
369370 Contributor :: SimpleName ( name) => name. to_string ( ) ,
370371 Contributor :: StructuredName ( contributor) => {
@@ -397,28 +398,33 @@ fn display_and_sort_names() {
397398 given_name : "John" . to_string ( ) ,
398399 family_name : "Doe" . to_string ( ) ,
399400 } ) ;
400- let options = StyleOptions :: default ( ) ;
401+ let options = Config :: default ( ) ;
401402 assert_eq ! ( simple. names( options, false ) , "John Doe" ) ;
402- let options = StyleOptions :: default ( ) ;
403+ let options = Config :: default ( ) ;
403404 assert_eq ! (
404405 simple. names( options, true ) ,
405406 "John Doe" ,
406407 "as_sorted=true should not affect a simple name"
407408 ) ;
408- let options = StyleOptions :: default ( ) ;
409+ let options = Config :: default ( ) ;
409410 assert_eq ! ( structured. names( options, false ) , "John Doe" ) ;
410- let options = StyleOptions :: default ( ) ;
411+ let options = Config :: default ( ) ;
411412 assert_eq ! ( structured. names( options, true ) , "Doe, John" ) ;
412413}
413414
414415impl NameList for ContributorList {
415- fn names_list ( & self , options : StyleOptions , as_sorted : bool ) -> String {
416+ fn names_list ( & self , options : Config , as_sorted : bool ) -> String {
416417 let names: Vec < String > = self
417418 . 0
418419 . iter ( )
419420 . enumerate ( )
420421 . map ( |( i, c) | {
421- let as_sorted_config = match options. contributors . display_as_sort {
422+ let as_sorted_config = match options
423+ . contributors
424+ . clone ( )
425+ . unwrap_or_default ( )
426+ . display_as_sort
427+ {
422428 style:: options:: DisplayAsSort :: All => true ,
423429 style:: options:: DisplayAsSort :: First => i == 0 ,
424430 style:: options:: DisplayAsSort :: None => false ,
@@ -440,9 +446,9 @@ fn contributor_list() {
440446 Contributor :: SimpleName ( "John Doe" . to_string( ) ) ,
441447 Contributor :: SimpleName ( "Jane Doe" . to_string( ) ) ,
442448 ] ) ;
443- let options = StyleOptions :: default ( ) ;
449+ let options = Config :: default ( ) ;
444450 assert_eq ! ( contributor_list. names_list( options, false ) , "John Doe, Jane Doe" ) ;
445- let options = StyleOptions :: default ( ) ;
451+ let options = Config :: default ( ) ;
446452 assert_eq ! (
447453 contributor_list. names_list( options, true ) ,
448454 "John Doe, Jane Doe" ,
@@ -458,16 +464,16 @@ fn contributor_list() {
458464 family_name: "Doe" . to_string( ) ,
459465 } ) ,
460466 ] ) ;
461- let options = StyleOptions :: default ( ) ;
467+ let options = Config :: default ( ) ;
462468 assert_eq ! ( structured_name_list. names_list( options, false ) , "John Doe, Jane Doe" ) ;
463- let options = StyleOptions :: default ( ) ;
469+ let options = Config :: default ( ) ;
464470 assert_eq ! ( structured_name_list. names_list( options, true ) , "Doe, John, Doe, Jane" ) ;
465- let options = StyleOptions {
466- contributors : style:: options:: StyleContributors {
471+ let options = Config {
472+ contributors : Some ( style:: options:: Contributors {
467473 display_as_sort : style:: options:: DisplayAsSort :: First ,
468- ..style:: options:: StyleContributors :: default ( )
469- } ,
470- ..style:: options:: StyleOptions :: default ( )
474+ ..style:: options:: Contributors :: default ( )
475+ } ) ,
476+ ..style:: options:: Config :: default ( )
471477 } ;
472478 assert_eq ! ( structured_name_list. names_list( options, false ) , "Doe, John, Jane Doe" ) ;
473479}
0 commit comments