From 8fc8f5c95449127b6ad0e0323de836e29592c5ec Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Fri, 20 May 2022 21:01:22 +0200 Subject: [PATCH] Format code in doc comments (#1899) --- components/calendar/README.md | 24 ++-- components/calendar/src/buddhist.rs | 15 +-- components/calendar/src/coptic.rs | 15 +-- components/calendar/src/ethiopic.rs | 15 +-- components/calendar/src/gregorian.rs | 27 ++--- components/calendar/src/indian.rs | 15 +-- components/calendar/src/iso.rs | 15 +-- components/calendar/src/japanese.rs | 15 ++- components/calendar/src/julian.rs | 15 +-- components/calendar/src/lib.rs | 24 ++-- components/calendar/src/types.rs | 2 +- components/datetime/README.md | 20 ++-- components/datetime/src/datetime.rs | 18 ++- components/datetime/src/fields/length.rs | 2 +- components/datetime/src/format/datetime.rs | 4 +- components/datetime/src/lib.rs | 20 ++-- components/datetime/src/mock/mod.rs | 8 +- components/datetime/src/mock/time_zone.rs | 9 +- .../datetime/src/mock/zoned_datetime.rs | 15 +-- components/datetime/src/options/components.rs | 7 +- components/datetime/src/options/length.rs | 106 +++++++---------- components/datetime/src/options/mod.rs | 4 +- .../datetime/src/pattern/runtime/generic.rs | 11 +- components/datetime/src/time_zone.rs | 91 +++++++------- components/datetime/src/zoned_datetime.rs | 68 ++++++++--- components/decimal/src/options.rs | 4 +- components/icu/README.md | 13 +- components/icu/src/lib.rs | 89 +++++++------- components/list/README.md | 6 +- components/list/src/lib.rs | 8 +- components/locale_canonicalizer/README.md | 29 ++--- components/locale_canonicalizer/src/lib.rs | 29 ++--- .../src/locale_canonicalizer.rs | 59 ++++------ components/locid/README.md | 13 +- components/locid/src/extensions/mod.rs | 27 ++--- components/locid/src/extensions/other/key.rs | 9 +- components/locid/src/extensions/other/mod.rs | 25 ++-- .../locid/src/extensions/private/key.rs | 9 +- .../locid/src/extensions/private/mod.rs | 32 ++--- .../locid/src/extensions/transform/fields.rs | 48 +++----- .../locid/src/extensions/transform/key.rs | 9 +- .../locid/src/extensions/transform/mod.rs | 30 ++--- .../locid/src/extensions/transform/value.rs | 9 +- .../locid/src/extensions/unicode/attribute.rs | 9 +- .../src/extensions/unicode/attributes.rs | 19 ++- .../locid/src/extensions/unicode/key.rs | 6 +- .../locid/src/extensions/unicode/keywords.rs | 74 +++++------- .../locid/src/extensions/unicode/mod.rs | 27 ++--- .../locid/src/extensions/unicode/value.rs | 12 +- components/locid/src/langid.rs | 25 ++-- components/locid/src/lib.rs | 13 +- components/locid/src/locale.rs | 27 +++-- components/locid/src/macros.rs | 16 +-- components/locid/src/subtags/language.rs | 21 ++-- components/locid/src/subtags/mod.rs | 16 +-- components/locid/src/subtags/region.rs | 18 +-- components/locid/src/subtags/script.rs | 15 +-- components/locid/src/subtags/variant.rs | 15 +-- components/locid/src/subtags/variants.rs | 31 ++--- components/locid/src/zerovec.rs | 46 ++++---- components/plurals/README.md | 2 +- components/plurals/src/error.rs | 1 - components/plurals/src/lib.rs | 35 +++--- components/plurals/src/operands.rs | 59 ++++++---- components/plurals/src/rules/mod.rs | 31 ++--- components/plurals/src/rules/reference/ast.rs | 65 ++++------ .../plurals/src/rules/reference/resolver.rs | 5 +- .../plurals/src/rules/reference/serializer.rs | 8 +- components/properties/README.md | 19 ++- components/properties/src/bidi.rs | 36 ++---- components/properties/src/lib.rs | 19 ++- components/properties/src/props.rs | 4 +- components/properties/src/script.rs | 74 ++++++------ docs/process/release.md | 2 + experimental/bies/README.md | 1 - experimental/bies/src/lib.rs | 1 - experimental/casemapping/src/internals.rs | 2 +- experimental/segmenter/README.md | 30 ++--- experimental/segmenter/src/lib.rs | 30 ++--- ffi/diplomat/README.md | 1 - .../cpp/include/ICU4XFixedDecimal.hpp | 4 - ffi/diplomat/src/fixed_decimal.rs | 4 - ffi/diplomat/src/lib.rs | 1 - provider/adapters/src/filter/impls.rs | 46 ++++---- provider/adapters/src/filter/mod.rs | 4 +- provider/adapters/src/fork/by_key.rs | 27 +++-- provider/adapters/src/fork/macros.rs | 5 +- provider/adapters/src/struct_provider.rs | 2 +- provider/blob/src/blob_data_provider.rs | 8 +- provider/blob/src/export/mod.rs | 42 ++++--- provider/blob/src/static_data_provider.rs | 10 +- provider/core/src/any.rs | 39 +++--- provider/core/src/buf.rs | 7 +- provider/core/src/data_provider.rs | 65 +++++----- provider/core/src/datagen/crabbake.rs | 13 +- provider/core/src/dynutil.rs | 24 ++-- provider/core/src/hello_world.rs | 2 +- provider/core/src/inv.rs | 4 +- provider/core/src/marker/mod.rs | 2 +- provider/core/src/resource.rs | 42 +++---- provider/core/src/serde/ser.rs | 13 +- provider/datagen/README.md | 3 +- provider/datagen/src/lib.rs | 3 +- provider/datagen/src/registry.rs | 23 ++-- provider/datagen/src/transform/cldr/mod.rs | 1 - .../datagen/src/transform/uprops/script.rs | 4 +- provider/fs/src/export/mod.rs | 34 +++--- provider/testdata/README.md | 7 +- provider/testdata/src/lib.rs | 7 +- utils/codepointtrie/README.md | 6 +- utils/codepointtrie/builder/README.md | 5 +- utils/codepointtrie/builder/src/lib.rs | 5 +- utils/codepointtrie/src/codepointtrie.rs | 18 ++- utils/codepointtrie/src/lib.rs | 6 +- utils/fixed_decimal/src/decimal.rs | 42 ++++--- utils/fixed_decimal/src/lib.rs | 7 +- utils/pattern/README.md | 15 +-- utils/pattern/src/interpolator/mod.rs | 93 ++++++++------- utils/pattern/src/lib.rs | 15 +-- utils/pattern/src/parser/error.rs | 11 +- utils/pattern/src/parser/mod.rs | 111 ++++++++++++------ utils/pattern/src/pattern/mod.rs | 76 ++++-------- utils/pattern/src/replacement.rs | 58 ++++----- utils/pattern/src/token.rs | 25 ++-- utils/tinystr/README.md | 2 +- utils/tinystr/src/ascii.rs | 111 ++++++------------ utils/tinystr/src/lib.rs | 2 +- utils/uniset/src/builder.rs | 12 +- utils/uniset/src/uniset.rs | 13 +- utils/writeable/README.md | 8 +- utils/writeable/src/impls.rs | 2 +- utils/writeable/src/lib.rs | 15 ++- utils/writeable/src/ops.rs | 14 +-- utils/yoke/src/either.rs | 24 +--- utils/yoke/src/trait_hack.rs | 16 ++- utils/yoke/src/yoke.rs | 35 ++---- utils/yoke/src/zero_from.rs | 9 +- utils/zerofrom/src/zero_from.rs | 6 +- utils/zerovec/README.md | 9 +- utils/zerovec/derive/src/utils.rs | 2 +- utils/zerovec/src/lib.rs | 74 ++++++++---- utils/zerovec/src/map/borrowed.rs | 14 +-- utils/zerovec/src/map/map.rs | 27 +++-- utils/zerovec/src/map2d/borrowed.rs | 12 +- utils/zerovec/src/map2d/map.rs | 16 +-- utils/zerovec/src/ule/chars.rs | 4 +- utils/zerovec/src/ule/custom.rs | 24 ++-- utils/zerovec/src/ule/encode.rs | 2 - utils/zerovec/src/ule/option.rs | 2 +- utils/zerovec/src/ule/tuple.rs | 9 +- utils/zerovec/src/varzerovec/slice.rs | 23 ++-- utils/zerovec/src/varzerovec/vec.rs | 35 +++--- utils/zerovec/src/zerovec/mod.rs | 45 ++++--- utils/zerovec/src/zerovec/slice.rs | 18 +-- 154 files changed, 1567 insertions(+), 1785 deletions(-) diff --git a/components/calendar/README.md b/components/calendar/README.md index cd97808c028..2cc3568c7d9 100644 --- a/components/calendar/README.md +++ b/components/calendar/README.md @@ -22,10 +22,7 @@ for working with dates, encompassing information about the day, month, year, as well as the calendar type. ```rust -use icu_calendar::{Date, - DateDuration, - DateDurationUnit, - types::IsoWeekday}; +use icu_calendar::{types::IsoWeekday, Date, DateDuration, DateDurationUnit}; // Creating ISO date: 1992-09-02. let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2) @@ -72,9 +69,7 @@ assert_eq!(mutated_date_iso.day_of_month().0, 27); Example of converting an ISO date across Indian and Buddhist calendars. ```rust -use icu_calendar::{Date, - buddhist::Buddhist, - indian::Indian}; +use icu_calendar::{buddhist::Buddhist, indian::Indian, Date}; // Creating ISO date: 1992-09-02. let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2) @@ -103,14 +98,10 @@ year, and calendar type. Additionally, `DateTime` objects contain an accessible `Time` object, including granularity of hour, minute, second, and nanosecond. ```rust -use icu_calendar::{DateTime, - DateDuration, - types::IsoWeekday, - types::IsoHour, - types::IsoMinute, - types::IsoSecond, - types::NanoSecond, - types::Time}; +use icu_calendar::{ + types::IsoHour, types::IsoMinute, types::IsoSecond, types::IsoWeekday, types::NanoSecond, + types::Time, DateDuration, DateTime, +}; // Creating ISO date: 1992-09-02 8:59 let mut datetime_iso = DateTime::new_iso_datetime_from_integers(1992, 9, 2, 8, 59, 0) @@ -128,8 +119,7 @@ assert_eq!(datetime_iso.time.nanosecond, NanoSecond::new_unchecked(0)); // Advancing date by 1 year, 2 months, 3 weeks, 4 days. datetime_iso.date.add(DateDuration::new(1, 2, 3, 4)); // New time of 14:30 -datetime_iso.time = Time::try_new(14, 30, 0, 0) - .expect("Failed to initialize Time instance."); +datetime_iso.time = Time::try_new(14, 30, 0, 0).expect("Failed to initialize Time instance."); assert_eq!(datetime_iso.date.year().number, 1993); assert_eq!(datetime_iso.date.month().number, 11); diff --git a/components/calendar/src/buddhist.rs b/components/calendar/src/buddhist.rs index 4809fa722c7..5bac6b04bfc 100644 --- a/components/calendar/src/buddhist.rs +++ b/components/calendar/src/buddhist.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Buddhist calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! buddhist::Buddhist}; +//! use icu::calendar::{ +//! buddhist::Buddhist, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -133,8 +133,8 @@ impl Date { /// use icu::calendar::Date; /// use std::convert::TryFrom; /// - /// let date_buddhist = Date::new_buddhist_date(1970, 1, 2) - /// .expect("Failed to initialize Buddhist Date instance."); + /// let date_buddhist = + /// Date::new_buddhist_date(1970, 1, 2).expect("Failed to initialize Buddhist Date instance."); /// /// assert_eq!(date_buddhist.year().number, 1970); /// assert_eq!(date_buddhist.month().number, 1); @@ -156,10 +156,7 @@ impl DateTime { /// Years are specified as BE years. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_buddhist = DateTime::new_buddhist_datetime(1970, 1, 2, 13, 1, 0) /// .expect("Failed to initialize Buddhist DateTime instance."); diff --git a/components/calendar/src/coptic.rs b/components/calendar/src/coptic.rs index a9bf11c7de2..27a06a6450a 100644 --- a/components/calendar/src/coptic.rs +++ b/components/calendar/src/coptic.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Coptic calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! coptic::Coptic}; +//! use icu::calendar::{ +//! coptic::Coptic, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -204,8 +204,8 @@ impl Date { /// ```rust /// use icu::calendar::Date; /// - /// let date_coptic = Date::new_coptic_date(1686, 5, 6) - /// .expect("Failed to initialize Coptic Date instance."); + /// let date_coptic = + /// Date::new_coptic_date(1686, 5, 6).expect("Failed to initialize Coptic Date instance."); /// /// assert_eq!(date_coptic.year().number, 1686); /// assert_eq!(date_coptic.month().number, 5); @@ -232,10 +232,7 @@ impl DateTime { /// Construct a new Coptic datetime from integers. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_coptic = DateTime::new_coptic_datetime(1686, 5, 6, 13, 1, 0) /// .expect("Failed to initialize Coptic DateTime instance."); diff --git a/components/calendar/src/ethiopic.rs b/components/calendar/src/ethiopic.rs index ea1ae8abcf7..8fe53cd36f1 100644 --- a/components/calendar/src/ethiopic.rs +++ b/components/calendar/src/ethiopic.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Ethiopic calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! ethiopic::Ethiopic}; +//! use icu::calendar::{ +//! ethiopic::Ethiopic, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -218,8 +218,8 @@ impl Date { /// ```rust /// use icu::calendar::Date; /// - /// let date_ethiopic = Date::new_ethiopic_date(2014, 8, 25) - /// .expect("Failed to initialize Ethopic Date instance."); + /// let date_ethiopic = + /// Date::new_ethiopic_date(2014, 8, 25).expect("Failed to initialize Ethopic Date instance."); /// /// assert_eq!(date_ethiopic.year().number, 2014); /// assert_eq!(date_ethiopic.month().number, 8); @@ -254,10 +254,7 @@ impl DateTime { /// Construct a new Ethiopic datetime from integers. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_ethiopic = DateTime::new_ethiopic_datetime(2014, 8, 25, 13, 1, 0, 0) /// .expect("Failed to initialize Ethiopic DateTime instance."); diff --git a/components/calendar/src/gregorian.rs b/components/calendar/src/gregorian.rs index a3d1c1f586c..b6a1eb3a1f0 100644 --- a/components/calendar/src/gregorian.rs +++ b/components/calendar/src/gregorian.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Gregorian calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! gregorian::Gregorian}; +//! use icu::calendar::{ +//! gregorian::Gregorian, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -125,17 +125,12 @@ impl Date { /// Years are specified as ISO years. /// /// ```rust - /// use icu::calendar::{Date, - /// iso::IsoYear, - /// iso::IsoMonth, - /// iso::IsoDay}; + /// use icu::calendar::{iso::IsoDay, iso::IsoMonth, iso::IsoYear, Date}; /// use std::convert::TryFrom; /// /// let iso_year = IsoYear(1970); - /// let iso_month = IsoMonth::try_from(1) - /// .expect("Failed to initialize IsoMonth instance."); - /// let iso_day = IsoDay::try_from(2) - /// .expect("Failed to initialize IsoDay instance."); + /// let iso_month = IsoMonth::try_from(1).expect("Failed to initialize IsoMonth instance."); + /// let iso_day = IsoDay::try_from(2).expect("Failed to initialize IsoDay instance."); /// /// // Conversion from ISO to Gregorian /// let date_gregorian = Date::new_gregorian_date(iso_year, iso_month, iso_day) @@ -160,13 +155,11 @@ impl DateTime { /// Years are specified as ISO years. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// - /// let datetime_gregorian = DateTime::new_gregorian_datetime_from_integers(1970, 1, 2, 13, 1, 0, 0) - /// .expect("Failed to initialize Gregorian DateTime instance."); + /// let datetime_gregorian = + /// DateTime::new_gregorian_datetime_from_integers(1970, 1, 2, 13, 1, 0, 0) + /// .expect("Failed to initialize Gregorian DateTime instance."); /// /// assert_eq!(datetime_gregorian.date.year().number, 1970); /// assert_eq!(datetime_gregorian.date.month().number, 1); diff --git a/components/calendar/src/indian.rs b/components/calendar/src/indian.rs index 21ab1d1928a..b7082a233e4 100644 --- a/components/calendar/src/indian.rs +++ b/components/calendar/src/indian.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Indian national calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! indian::Indian}; +//! use icu::calendar::{ +//! indian::Indian, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -187,8 +187,8 @@ impl Date { /// ```rust /// use icu::calendar::Date; /// - /// let date_indian = Date::new_indian_date(1891, 10, 12) - /// .expect("Failed to initialize Indian Date instance."); + /// let date_indian = + /// Date::new_indian_date(1891, 10, 12).expect("Failed to initialize Indian Date instance."); /// /// assert_eq!(date_indian.year().number, 1891); /// assert_eq!(date_indian.month().number, 10); @@ -215,10 +215,7 @@ impl DateTime { /// Construct a new Indian datetime from integers. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_indian = DateTime::new_indian_datetime(1891, 10, 12, 13, 1, 0) /// .expect("Failed to initialize Indian DateTime instance."); diff --git a/components/calendar/src/iso.rs b/components/calendar/src/iso.rs index 26fc8c25c05..2564b2b9574 100644 --- a/components/calendar/src/iso.rs +++ b/components/calendar/src/iso.rs @@ -5,8 +5,7 @@ //! This module contains types and implementations for the ISO calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond}; +//! use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime}; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -331,15 +330,12 @@ impl Date { /// Construct a new ISO Date. /// /// ```rust - /// use icu::calendar::{Date, - /// iso::IsoYear, iso::IsoMonth, iso::IsoDay}; + /// use icu::calendar::{iso::IsoDay, iso::IsoMonth, iso::IsoYear, Date}; /// use std::convert::TryFrom; /// /// let iso_year = IsoYear(1996); - /// let iso_month = IsoMonth::try_from(2) - /// .expect("Failed to initialize IsoMonth instance."); - /// let iso_day = IsoDay::try_from(3) - /// .expect("Failed to initialize IsoDay instance."); + /// let iso_month = IsoMonth::try_from(2).expect("Failed to initialize IsoMonth instance."); + /// let iso_day = IsoDay::try_from(3).expect("Failed to initialize IsoDay instance."); /// /// // Creation of ISO date /// let date_iso = Date::new_iso_date(iso_year, iso_month, iso_day) @@ -389,8 +385,7 @@ impl DateTime { /// Construct a new ISO datetime from integers. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, types::IsoMinute, types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_iso = DateTime::new_iso_datetime_from_integers(1970, 1, 2, 13, 1, 0) /// .expect("Failed to initialize ISO DateTime instance."); diff --git a/components/calendar/src/japanese.rs b/components/calendar/src/japanese.rs index 875d164e6ba..787d724548f 100644 --- a/components/calendar/src/japanese.rs +++ b/components/calendar/src/japanese.rs @@ -5,16 +5,16 @@ //! This module contains types and implementations for the Japanese calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, types::Era, -//! japanese::Japanese}; +//! use icu::calendar::{ +//! japanese::Japanese, types::Era, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, +//! DateTime, +//! }; //! use tinystr::tinystr; //! //! // `icu_testdata::get_provider` contains information specifying era dates. //! // Production code should probably use its own data provider //! let provider = icu_testdata::get_provider(); -//! let japanese_calendar = Japanese::try_new(&provider) -//! .expect("Cannot load japanese data"); +//! let japanese_calendar = Japanese::try_new(&provider).expect("Cannot load japanese data"); //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -36,7 +36,10 @@ //! assert_eq!(datetime_japanese.date.year().number, 45); //! assert_eq!(datetime_japanese.date.month().number, 1); //! assert_eq!(datetime_japanese.date.day_of_month().0, 2); -//! assert_eq!(datetime_japanese.date.year().era, Era(tinystr!(16, "showa"))); +//! assert_eq!( +//! datetime_japanese.date.year().era, +//! Era(tinystr!(16, "showa")) +//! ); //! assert_eq!(datetime_japanese.time.hour, IsoHour::new_unchecked(13)); //! assert_eq!(datetime_japanese.time.minute, IsoMinute::new_unchecked(1)); //! assert_eq!(datetime_japanese.time.second, IsoSecond::new_unchecked(0)); diff --git a/components/calendar/src/julian.rs b/components/calendar/src/julian.rs index 65b6c92438a..eb03972fb4a 100644 --- a/components/calendar/src/julian.rs +++ b/components/calendar/src/julian.rs @@ -5,9 +5,9 @@ //! This module contains types and implementations for the Julian calendar. //! //! ```rust -//! use icu::calendar::{Date, DateTime, -//! types::IsoHour, types::IsoMinute, types::IsoSecond, -//! julian::Julian}; +//! use icu::calendar::{ +//! julian::Julian, types::IsoHour, types::IsoMinute, types::IsoSecond, Date, DateTime, +//! }; //! //! // `Date` type //! let date_iso = Date::new_iso_date_from_integers(1970, 1, 2) @@ -233,8 +233,8 @@ impl Date { /// ```rust /// use icu::calendar::Date; /// - /// let date_julian = Date::new_julian_date(1969, 12, 20) - /// .expect("Failed to initialize Julian Date instance."); + /// let date_julian = + /// Date::new_julian_date(1969, 12, 20).expect("Failed to initialize Julian Date instance."); /// /// assert_eq!(date_julian.year().number, 1969); /// assert_eq!(date_julian.month().number, 12); @@ -263,10 +263,7 @@ impl DateTime { /// Construct a new Julian datetime from integers. /// /// ```rust - /// use icu::calendar::{DateTime, - /// types::IsoHour, - /// types::IsoMinute, - /// types::IsoSecond}; + /// use icu::calendar::{types::IsoHour, types::IsoMinute, types::IsoSecond, DateTime}; /// /// let datetime_julian = DateTime::new_julian_datetime(1969, 12, 20, 13, 1, 0) /// .expect("Failed to initialize Julian DateTime instance."); diff --git a/components/calendar/src/lib.rs b/components/calendar/src/lib.rs index b8f2d4ceaa5..9b547e8cce0 100644 --- a/components/calendar/src/lib.rs +++ b/components/calendar/src/lib.rs @@ -24,10 +24,7 @@ //! as well as the calendar type. //! //! ```rust -//! use icu_calendar::{Date, -//! DateDuration, -//! DateDurationUnit, -//! types::IsoWeekday}; +//! use icu_calendar::{types::IsoWeekday, Date, DateDuration, DateDurationUnit}; //! //! // Creating ISO date: 1992-09-02. //! let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2) @@ -74,9 +71,7 @@ //! Example of converting an ISO date across Indian and Buddhist calendars. //! //! ```rust -//! use icu_calendar::{Date, -//! buddhist::Buddhist, -//! indian::Indian}; +//! use icu_calendar::{buddhist::Buddhist, indian::Indian, Date}; //! //! // Creating ISO date: 1992-09-02. //! let mut date_iso = Date::new_iso_date_from_integers(1992, 9, 2) @@ -105,14 +100,10 @@ //! `Time` object, including granularity of hour, minute, second, and nanosecond. //! //! ```rust -//! use icu_calendar::{DateTime, -//! DateDuration, -//! types::IsoWeekday, -//! types::IsoHour, -//! types::IsoMinute, -//! types::IsoSecond, -//! types::NanoSecond, -//! types::Time}; +//! use icu_calendar::{ +//! types::IsoHour, types::IsoMinute, types::IsoSecond, types::IsoWeekday, types::NanoSecond, +//! types::Time, DateDuration, DateTime, +//! }; //! //! // Creating ISO date: 1992-09-02 8:59 //! let mut datetime_iso = DateTime::new_iso_datetime_from_integers(1992, 9, 2, 8, 59, 0) @@ -130,8 +121,7 @@ //! // Advancing date by 1 year, 2 months, 3 weeks, 4 days. //! datetime_iso.date.add(DateDuration::new(1, 2, 3, 4)); //! // New time of 14:30 -//! datetime_iso.time = Time::try_new(14, 30, 0, 0) -//! .expect("Failed to initialize Time instance."); +//! datetime_iso.time = Time::try_new(14, 30, 0, 0).expect("Failed to initialize Time instance."); //! //! assert_eq!(datetime_iso.date.year().number, 1993); //! assert_eq!(datetime_iso.date.month().number, 11); diff --git a/components/calendar/src/types.rs b/components/calendar/src/types.rs index 05a66328d72..71acb976e5f 100644 --- a/components/calendar/src/types.rs +++ b/components/calendar/src/types.rs @@ -348,7 +348,7 @@ impl FromStr for GmtOffset { fn from_str(input: &str) -> Result { let offset_sign = match input.chars().next() { Some('+') => 1, - /* ASCII */ Some('-') => -1, + /* ASCII */ Some('-') => -1, /* U+2212 */ Some('−') => -1, Some('Z') => return Ok(Self(0)), _ => return Err(DateTimeError::InvalidTimeZoneOffset), diff --git a/components/datetime/README.md b/components/datetime/README.md index c936ed3368c..5c3d8db858d 100644 --- a/components/datetime/README.md +++ b/components/datetime/README.md @@ -11,21 +11,24 @@ used to quickly format any date and time provided. ## Examples ```rust -use icu::locid::locale; use icu::calendar::Gregorian; -use icu::datetime::{DateTimeFormat, DateTimeFormatOptions, mock::parse_gregorian_from_str, options::length}; +use icu::datetime::{ + mock::parse_gregorian_from_str, options::length, DateTimeFormat, DateTimeFormatOptions, +}; +use icu::locid::locale; let provider = icu_testdata::get_provider(); // See the next code example for a more ergonomic example with .into(). -let options = DateTimeFormatOptions::Length(length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short)); +let options = DateTimeFormatOptions::Length(length::Bag::from_date_time_style( + length::Date::Medium, + length::Time::Short, +)); let dtf = DateTimeFormat::::try_new(locale!("en"), &provider, &options) .expect("Failed to create DateTimeFormat instance."); - -let date = parse_gregorian_from_str("2020-09-12T12:35:00") - .expect("Failed to parse date."); +let date = parse_gregorian_from_str("2020-09-12T12:35:00").expect("Failed to parse date."); let formatted_date = dtf.format(&date); assert_eq!(formatted_date.to_string(), "Sep 12, 2020, 12:35 PM"); @@ -36,8 +39,9 @@ convert a [`options::length::Bag`] into a [`DateTimeFormatOptions::Length`]. ```rust use icu::calendar::Gregorian; -use icu::datetime::{DateTimeFormat, DateTimeFormatOptions, options::length}; -let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); +use icu::datetime::{options::length, DateTimeFormat, DateTimeFormatOptions}; +let options = + length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); let dtf = DateTimeFormat::::try_new(locale, &provider, &options); ``` diff --git a/components/datetime/src/datetime.rs b/components/datetime/src/datetime.rs index 3212c27650d..53ed9545479 100644 --- a/components/datetime/src/datetime.rs +++ b/components/datetime/src/datetime.rs @@ -32,9 +32,9 @@ use crate::{date::DateTimeInput, CldrCalendar, DateTimeFormatError, FormattedDat /// # Examples /// /// ``` -/// use icu::locid::locale; -/// use icu::datetime::{DateTimeFormat, options::length}; /// use icu::calendar::{DateTime, Gregorian}; +/// use icu::datetime::{options::length, DateTimeFormat}; +/// use icu::locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; @@ -44,7 +44,6 @@ use crate::{date::DateTimeInput, CldrCalendar, DateTimeFormatError, FormattedDat /// let dtf = DateTimeFormat::::try_new(locale!("en"), &provider, &options.into()) /// .expect("Failed to create DateTimeFormat instance."); /// -/// /// let datetime = DateTime::new_gregorian_datetime_from_integers(2020, 9, 1, 12, 34, 28, 0) /// .expect("Failed to construct DateTime."); /// @@ -63,9 +62,9 @@ impl DateTimeFormat { /// # Examples /// /// ``` - /// use icu::locid::locale; /// use icu::calendar::Gregorian; /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; + /// use icu::locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; @@ -110,8 +109,8 @@ impl DateTimeFormat { /// # Examples /// /// ``` - /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu::calendar::{DateTime, Gregorian}; + /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); /// # let provider = InvariantDataProvider; @@ -144,8 +143,8 @@ impl DateTimeFormat { /// # Examples /// /// ``` - /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu::calendar::{DateTime, Gregorian}; + /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); /// # let provider = InvariantDataProvider; @@ -176,8 +175,8 @@ impl DateTimeFormat { /// # Examples /// /// ``` - /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu::calendar::{DateTime, Gregorian}; + /// use icu::datetime::{DateTimeFormat, DateTimeFormatOptions}; /// use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); /// # let provider = InvariantDataProvider; @@ -221,10 +220,7 @@ impl DateTimeFormat { /// expected_components_bag.month = Some(components::Month::Short); /// expected_components_bag.day = Some(components::Day::NumericDayOfMonth); /// - /// assert_eq!( - /// dtf.resolve_components(), - /// expected_components_bag - /// ); + /// assert_eq!(dtf.resolve_components(), expected_components_bag); /// ``` pub fn resolve_components(&self) -> components::Bag { self.0.resolve_components() diff --git a/components/datetime/src/fields/length.rs b/components/datetime/src/fields/length.rs index 5c77240a7e7..4df3f9ba8d2 100644 --- a/components/datetime/src/fields/length.rs +++ b/components/datetime/src/fields/length.rs @@ -38,7 +38,7 @@ impl FieldLength { FieldLength::Wide => 4, FieldLength::Narrow => 5, FieldLength::Six => 6, - FieldLength::Fixed(p) => 128 + p.min(&127), // truncate to at most 127 digits to avoid overflow + FieldLength::Fixed(p) => 128 + p.min(&127), /* truncate to at most 127 digits to avoid overflow */ } } diff --git a/components/datetime/src/format/datetime.rs b/components/datetime/src/format/datetime.rs index 6ff205ae51d..f1cee86c85a 100644 --- a/components/datetime/src/format/datetime.rs +++ b/components/datetime/src/format/datetime.rs @@ -31,9 +31,9 @@ use writeable::Writeable; /// # Examples /// /// ``` -/// use icu::locid::locale; -/// use icu::datetime::DateTimeFormat; /// use icu::calendar::{DateTime, Gregorian}; +/// use icu::datetime::DateTimeFormat; +/// use icu::locid::locale; /// # let provider = icu_provider::inv::InvariantDataProvider; /// # let options = icu::datetime::DateTimeFormatOptions::default(); /// let dtf = DateTimeFormat::::try_new(locale!("en"), &provider, &options) diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index 084f0e1dbc0..da210a58c89 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -15,21 +15,24 @@ //! # Examples //! //! ``` -//! use icu::locid::locale; //! use icu::calendar::Gregorian; -//! use icu::datetime::{DateTimeFormat, DateTimeFormatOptions, mock::parse_gregorian_from_str, options::length}; +//! use icu::datetime::{ +//! mock::parse_gregorian_from_str, options::length, DateTimeFormat, DateTimeFormatOptions, +//! }; +//! use icu::locid::locale; //! //! let provider = icu_testdata::get_provider(); //! //! // See the next code example for a more ergonomic example with .into(). -//! let options = DateTimeFormatOptions::Length(length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short)); +//! let options = DateTimeFormatOptions::Length(length::Bag::from_date_time_style( +//! length::Date::Medium, +//! length::Time::Short, +//! )); //! //! let dtf = DateTimeFormat::::try_new(locale!("en"), &provider, &options) //! .expect("Failed to create DateTimeFormat instance."); //! -//! -//! let date = parse_gregorian_from_str("2020-09-12T12:35:00") -//! .expect("Failed to parse date."); +//! let date = parse_gregorian_from_str("2020-09-12T12:35:00").expect("Failed to parse date."); //! //! let formatted_date = dtf.format(&date); //! assert_eq!(formatted_date.to_string(), "Sep 12, 2020, 12:35 PM"); @@ -40,10 +43,11 @@ //! //! ``` //! use icu::calendar::Gregorian; -//! use icu::datetime::{DateTimeFormat, DateTimeFormatOptions, options::length}; +//! use icu::datetime::{options::length, DateTimeFormat, DateTimeFormatOptions}; //! # let provider = icu_testdata::get_provider(); //! # let locale = icu::locid::locale!("en"); -//! let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); +//! let options = +//! length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); //! //! let dtf = DateTimeFormat::::try_new(locale, &provider, &options); //! ``` diff --git a/components/datetime/src/mock/mod.rs b/components/datetime/src/mock/mod.rs index 320146c4fb3..16d744df0f0 100644 --- a/components/datetime/src/mock/mod.rs +++ b/components/datetime/src/mock/mod.rs @@ -22,8 +22,8 @@ pub mod zoned_datetime; /// use icu::datetime::mock::parse_gregorian_from_str; /// use icu_calendar::{DateTime, Gregorian}; /// -/// let date: DateTime = parse_gregorian_from_str("2020-10-14T13:21:00") -/// .expect("Failed to parse a datetime."); +/// let date: DateTime = +/// parse_gregorian_from_str("2020-10-14T13:21:00").expect("Failed to parse a datetime."); /// ``` /// /// Optionally, fractional seconds can be specified: `YYYY-MM-DDThh:mm:ss.SSS`. @@ -32,8 +32,8 @@ pub mod zoned_datetime; /// use icu::datetime::mock::parse_gregorian_from_str; /// use icu_calendar::{DateTime, Gregorian}; /// -/// let date: DateTime = parse_gregorian_from_str("2020-10-14T13:21:00.101") -/// .expect("Failed to parse a datetime."); +/// let date: DateTime = +/// parse_gregorian_from_str("2020-10-14T13:21:00.101").expect("Failed to parse a datetime."); /// assert_eq!(u32::from(date.time.nanosecond), 101_000_000); /// ``` pub fn parse_gregorian_from_str(input: &str) -> Result, DateTimeError> { diff --git a/components/datetime/src/mock/time_zone.rs b/components/datetime/src/mock/time_zone.rs index 6654645d57d..47c2b674fd9 100644 --- a/components/datetime/src/mock/time_zone.rs +++ b/components/datetime/src/mock/time_zone.rs @@ -20,18 +20,17 @@ use core::str::FromStr; /// # Examples /// /// ``` -/// use icu::datetime::mock::time_zone::MockTimeZone; /// use icu::datetime::date::GmtOffset; +/// use icu::datetime::mock::time_zone::MockTimeZone; /// /// let tz1 = MockTimeZone::new( /// GmtOffset::default(), -/// /* time_zone_id */ None, -/// /* metazone_id */ None, +/// /* time_zone_id */ None, +/// /* metazone_id */ None, /// /* time_variaint */ None, /// ); /// -/// let tz2: MockTimeZone = "+05:00".parse() -/// .expect("Failed to parse a time zone."); +/// let tz2: MockTimeZone = "+05:00".parse().expect("Failed to parse a time zone."); /// ``` #[derive(Debug, Default)] #[allow(clippy::exhaustive_structs)] // this type will not add fields (it is largely an example type) diff --git a/components/datetime/src/mock/zoned_datetime.rs b/components/datetime/src/mock/zoned_datetime.rs index 863c5dd8622..2b683a1b7cf 100644 --- a/components/datetime/src/mock/zoned_datetime.rs +++ b/components/datetime/src/mock/zoned_datetime.rs @@ -26,19 +26,19 @@ use icu_calendar::{DateTime, Gregorian}; /// # Examples /// /// ``` +/// use icu::calendar::{DateTime, Gregorian}; /// use icu::datetime::mock::parse_gregorian_from_str; /// use icu::datetime::mock::time_zone::MockTimeZone; -/// use icu::calendar::{DateTime, Gregorian}; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; /// -/// let dt: DateTime = parse_gregorian_from_str("2020-10-14T13:21:00") -/// .expect("Failed to parse a datetime."); +/// let dt: DateTime = +/// parse_gregorian_from_str("2020-10-14T13:21:00").expect("Failed to parse a datetime."); /// -/// let tz: MockTimeZone = "+05:00".parse() -/// .expect("Failed to parse a time zone."); +/// let tz: MockTimeZone = "+05:00".parse().expect("Failed to parse a time zone."); /// /// let zdt1 = MockZonedDateTime::new(dt, tz); -/// let zdt2: MockZonedDateTime = "2020-10-14T13:21:00+05:00".parse() +/// let zdt2: MockZonedDateTime = "2020-10-14T13:21:00+05:00" +/// .parse() /// .expect("Failed to parse a zoned datetime."); /// ``` /// [`ZonedDateTimeFormat`]: crate::zoned_datetime::ZonedDateTimeFormat @@ -77,7 +77,8 @@ impl FromStr for MockZonedDateTime { /// ``` /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; /// - /// let date: MockZonedDateTime = "2020-10-14T13:21:00+05:30".parse() + /// let date: MockZonedDateTime = "2020-10-14T13:21:00+05:30" + /// .parse() /// .expect("Failed to parse a zoned datetime."); /// ``` fn from_str(input: &str) -> Result { diff --git a/components/datetime/src/options/components.rs b/components/datetime/src/options/components.rs index 58b8266d25c..9060778b58d 100644 --- a/components/datetime/src/options/components.rs +++ b/components/datetime/src/options/components.rs @@ -41,8 +41,8 @@ //! # Examples //! //! ``` -//! use icu::datetime::DateTimeFormatOptions; //! use icu::datetime::options::components; +//! use icu::datetime::DateTimeFormatOptions; //! //! let mut bag = components::Bag::default(); //! bag.year = Some(components::Year::Numeric); @@ -59,8 +59,8 @@ //! Or the options can be inferred through the `.into()` trait. //! //! ``` -//! use icu::datetime::DateTimeFormatOptions; //! use icu::datetime::options::components; +//! use icu::datetime::DateTimeFormatOptions; //! let options: DateTimeFormatOptions = components::Bag::default().into(); //! ``` //! @@ -472,13 +472,11 @@ pub enum Day { #[non_exhaustive] pub enum TimeZoneName { // UTS-35 fields: z..zzz - // /// Short localized form, without the location. (e.g.: PST, GMT-8) ShortSpecific, // UTS-35 fields: zzzz // Per UTS-35: [long form] specific non-location (falling back to long localized GMT) - // /// Long localized form, without the location (e.g., Pacific Standard Time, Nordamerikanische Westküsten-Normalzeit) LongSpecific, @@ -489,7 +487,6 @@ pub enum TimeZoneName { // hour-format for the locale, and ICU4X uses the preferred one. // e.g. // https://github.com/unicode-org/cldr-json/blob/c23635f13946292e40077fd62aee6a8e122e7689/cldr-json/cldr-dates-full/main/es-MX/timeZoneNames.json#L13 - // /// Localized GMT format, in the locale's preferred hour format. (e.g., GMT-0800), GmtOffset, diff --git a/components/datetime/src/options/length.rs b/components/datetime/src/options/length.rs index 805934f1890..c76a4418512 100644 --- a/components/datetime/src/options/length.rs +++ b/components/datetime/src/options/length.rs @@ -18,12 +18,12 @@ //! # Examples //! //! ``` -//! use icu::datetime::DateTimeFormatOptions; //! use icu::datetime::options::length; +//! use icu::datetime::DateTimeFormatOptions; //! //! let bag = length::Bag::from_date_time_style( //! length::Date::Medium, // "medium" date connector will be used -//! length::Time::Short +//! length::Time::Short, //! ); //! //! let options = DateTimeFormatOptions::Length(bag); @@ -32,8 +32,8 @@ //! Or the options can be inferred through the [`Into`] trait. //! //! ``` -//! use icu::datetime::DateTimeFormatOptions; //! use icu::datetime::options::length; +//! use icu::datetime::DateTimeFormatOptions; //! let options: DateTimeFormatOptions = length::Bag::default().into(); //! ``` //! @@ -54,8 +54,8 @@ use serde::{Deserialize, Serialize}; /// # Examples /// /// ``` -/// use icu::datetime::DateTimeFormatOptions; /// use icu::datetime::options::length; +/// use icu::datetime::DateTimeFormatOptions; /// /// let bag = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short); /// @@ -65,8 +65,8 @@ use serde::{Deserialize, Serialize}; /// Or the options can be inferred through the [`Into`] trait. /// /// ``` -/// use icu::datetime::DateTimeFormatOptions; /// use icu::datetime::options::length; +/// use icu::datetime::DateTimeFormatOptions; /// let options: DateTimeFormatOptions = length::Bag::default().into(); /// ``` /// @@ -164,52 +164,44 @@ pub enum Date { /// /// # Examples /// - /// ``` - /// "Tuesday, January 21, 2020"; // en-US - /// "wtorek, 21 stycznia, 2020"; // pl - /// "الثلاثاء، ٢١ يناير ٢٠٢٠"; // ar - /// "вторник, 21 января 2020 г."; // ru - /// "2020年1月21日火曜日"; // ja - /// ``` + /// * Tuesday, January 21, 2020 (`en-US`) + /// * wtorek, 21 stycznia, 2020 (`pl`) + /// * الثلاثاء، ٢١ يناير ٢٠٢٠ (`ar`) + /// * вторник, 21 января 2020 г. (`ru`) + /// * 2020年1月21日火曜日 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "full"))] Full, /// Long length, with wide month name. /// /// # Examples /// - /// ``` - /// "September 10, 2020"; // en-US - /// "10 września 2020"; // pl - /// "١٠ سبتمبر ٢٠٢٠"; // ar - /// "10 сентября 2020 г."; // ru - /// "2020年9月10日"; // ja - /// ``` + /// * September 10, 2020 (`en-US`) + /// * 10 września 2020 (`pl`) + /// * ١٠ سبتمبر ٢٠٢٠ (`ar`) + /// * 10 сентября 2020 г. (`ru`) + /// * 2020年9月10日 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "long"))] Long, /// Medium length. /// /// # Examples /// - /// ``` - /// "Feb 20, 2020"; // en-US - /// "20 lut 2020"; // pl - /// "٢٠‏/٠٢‏/٢٠٢٠"; // ar - /// "20 февр. 2020 г."; // ru - /// "2020/02/20"; // ja - /// ``` + /// * Feb 20, 2020 (`en-US`) + /// * 20 lut 2020 (`pl`) + /// * ٢٠‏/٠٢‏/٢٠٢٠ (`ar`) + /// * 20 февр. 2020 г. (`ru`) + /// * 2020/02/20 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "medium"))] Medium, /// Short length, usually with numeric month. /// /// # Examples /// - /// ``` - /// "1/30/20"; // en-US - /// "30.01.2020"; // pl - /// "٣٠‏/١‏/٢٠٢٠"; // ar - /// "30.01.2020"; // ru - /// "2020/01/30"; // ja - /// ``` + /// * 1/30/20 (`en-US`) + /// * 30.01.2020 (`pl`) + /// * ٣٠‏/١‏/٢٠٢٠ (`ar`) + /// * 30.01.2020 (`ru`) + /// * 2020/01/30 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "short"))] Short, } @@ -244,52 +236,44 @@ pub enum Time { /// /// # Examples /// - /// ``` - /// "8:25:07 AM Pacific Standard Time"; // en-US - /// "08:25:07 czas pacyficzny standardowy"; // pl - /// "٨:٢٥:٠٧ ص توقيت المحيط الهادي الرسمي"; // ar - /// "08:25:07 Тихоокеанское стандартное время"; // ru - /// "8時25分07秒 アメリカ太平洋標準時"; // ja - /// ``` + /// * 8:25:07 AM Pacific Standard Time (`en-US`) + /// * 08:25:07 czas pacyficzny standardowy (`pl`) + /// * ٨:٢٥:٠٧ ص توقيت المحيط الهادي الرسمي (`ar`) + /// * 08:25:07 Тихоокеанское стандартное время (`ru`) + /// * 8時25分07秒 アメリカ太平洋標準時 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "full"))] Full, /// Full length, usually with short time-zone code. /// /// # Examples /// - /// ``` - /// "8:25:07 AM PST"; // en-US - /// "08:25:07 GMT-8"; // pl - /// "٨:٢٥:٠٧ ص غرينتش-٨"; // ar - /// "08:25:07 GMT-8"; // ru - /// "8:25:07 GMT-8"; // ja - /// ``` + /// * 8:25:07 AM PST (`en-US`) + /// * 08:25:07 GMT-8 (`pl`) + /// * ٨:٢٥:٠٧ ص غرينتش-٨ (`ar`) + /// * 08:25:07 GMT-8 (`ru`) + /// * 8:25:07 GMT-8 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "long"))] Long, /// Full length, usually with seconds. /// /// # Examples /// - /// ``` - /// "8:25:07 AM"; // en-US - /// "08:25:07"; // pl - /// "٨:٢٥:٠٧ ص"; // ar - /// "08:25:07"; // ru - /// "8:25:07"; // ja - /// ``` + /// * 8:25:07 AM (`en-US`) + /// * 08:25:07 (`pl`) + /// * ٨:٢٥:٠٧ ص (`ar`) + /// * 08:25:07 (`ru`) + /// * 8:25:07 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "medium"))] Medium, /// Full length, usually without seconds. /// /// # Examples /// - /// ``` - /// "8:25 AM"; // en-US - /// "08:25"; // pl - /// "٨:٢٥ ص"; // ar - /// "08:25"; // ru - /// "8:25"; // ja - /// ``` + /// * 8:25 AM (`en-US`) + /// * 08:25 (`pl`) + /// * ٨:٢٥ ص (`ar`) + /// * 08:25 (`ru`) + /// * 8:25 (`ja`) #[cfg_attr(feature = "serde", serde(rename = "short"))] Short, } diff --git a/components/datetime/src/options/mod.rs b/components/datetime/src/options/mod.rs index 61df92c34c8..0461631579b 100644 --- a/components/datetime/src/options/mod.rs +++ b/components/datetime/src/options/mod.rs @@ -15,7 +15,7 @@ //! # Examples //! //! ``` -//! use icu::datetime::{DateTimeFormatOptions, options::length}; +//! use icu::datetime::{options::length, DateTimeFormatOptions}; //! //! let bag = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short); //! ``` @@ -36,7 +36,7 @@ pub mod preferences; /// # Examples /// /// ``` -/// use icu::datetime::{DateTimeFormatOptions, options::length}; +/// use icu::datetime::{options::length, DateTimeFormatOptions}; /// /// let bag = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short); /// ``` diff --git a/components/datetime/src/pattern/runtime/generic.rs b/components/datetime/src/pattern/runtime/generic.rs index f978dd34b56..e154d1fdb72 100644 --- a/components/datetime/src/pattern/runtime/generic.rs +++ b/components/datetime/src/pattern/runtime/generic.rs @@ -27,13 +27,12 @@ impl<'data> GenericPattern<'data> { /// ``` /// use icu_datetime::pattern::runtime::{GenericPattern, Pattern}; /// - /// let date: Pattern = "Y-m-d".parse() - /// .expect("Failed to parse pattern"); - /// let time: Pattern = "HH:mm".parse() - /// .expect("Failed to parse pattern"); + /// let date: Pattern = "Y-m-d".parse().expect("Failed to parse pattern"); + /// let time: Pattern = "HH:mm".parse().expect("Failed to parse pattern"); /// - /// let glue: GenericPattern = "{1} 'at' {0}".parse() - /// .expect("Failed to parse generic pattern"); + /// let glue: GenericPattern = "{1} 'at' {0}" + /// .parse() + /// .expect("Failed to parse generic pattern"); /// assert_eq!( /// glue.combined(date, time) /// .expect("Failed to combine patterns") diff --git a/components/datetime/src/time_zone.rs b/components/datetime/src/time_zone.rs index 8144b9585ac..8aefe360922 100644 --- a/components/datetime/src/time_zone.rs +++ b/components/datetime/src/time_zone.rs @@ -61,23 +61,23 @@ where /// # Examples /// /// ``` -/// use icu_locid::locale; -/// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; /// use icu_datetime::date::GmtOffset; /// use icu_datetime::mock::time_zone::MockTimeZone; +/// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; +/// use icu_locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; /// -/// let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::GenericNonLocationLong, &provider, &TimeZoneFormatOptions::default()) -/// .expect("Failed to create TimeZoneFormat"); +/// let tzf = TimeZoneFormat::try_from_config( +/// locale!("en"), +/// TimeZoneFormatConfig::GenericNonLocationLong, +/// &provider, +/// &TimeZoneFormatOptions::default(), +/// ) +/// .expect("Failed to create TimeZoneFormat"); /// -/// let time_zone = MockTimeZone::new( -/// GmtOffset::default(), -/// None, -/// None, -/// None, -/// ); +/// let time_zone = MockTimeZone::new(GmtOffset::default(), None, None, None); /// /// let value = tzf.format_to_string(&time_zone); /// ``` @@ -349,14 +349,19 @@ impl TimeZoneFormat { /// # Examples /// /// ``` - /// use icu_locid::locale; - /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; /// use icu_datetime::mock::time_zone::MockTimeZone; + /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; + /// use icu_locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; /// - /// let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default()); + /// let tzf = TimeZoneFormat::try_from_config( + /// locale!("en"), + /// TimeZoneFormatConfig::LocalizedGMT, + /// &provider, + /// &TimeZoneFormatOptions::default(), + /// ); /// /// assert!(tzf.is_ok()); /// ``` @@ -600,23 +605,23 @@ impl TimeZoneFormat { /// # Examples /// /// ``` - /// use icu_locid::locale; - /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; /// use icu_datetime::date::GmtOffset; /// use icu_datetime::mock::time_zone::MockTimeZone; + /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; + /// use icu_locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; /// - /// let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default()) - /// .expect("Failed to create TimeZoneFormat"); + /// let tzf = TimeZoneFormat::try_from_config( + /// locale!("en"), + /// TimeZoneFormatConfig::LocalizedGMT, + /// &provider, + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create TimeZoneFormat"); /// - /// let time_zone = MockTimeZone::new( - /// GmtOffset::default(), - /// None, - /// None, - /// None, - /// ); + /// let time_zone = MockTimeZone::new(GmtOffset::default(), None, None, None); /// /// let _ = tzf.format(&time_zone); /// ``` @@ -636,23 +641,23 @@ impl TimeZoneFormat { /// # Examples /// /// ``` - /// use icu_locid::locale; - /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; /// use icu_datetime::date::GmtOffset; /// use icu_datetime::mock::time_zone::MockTimeZone; + /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; + /// use icu_locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; /// - /// let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default()) - /// .expect("Failed to create TimeZoneFormat"); + /// let tzf = TimeZoneFormat::try_from_config( + /// locale!("en"), + /// TimeZoneFormatConfig::LocalizedGMT, + /// &provider, + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create TimeZoneFormat"); /// - /// let time_zone = MockTimeZone::new( - /// GmtOffset::default(), - /// None, - /// None, - /// None, - /// ); + /// let time_zone = MockTimeZone::new(GmtOffset::default(), None, None, None); /// /// let mut buffer = String::new(); /// tzf.format_to_write(&mut buffer, &time_zone) @@ -673,23 +678,23 @@ impl TimeZoneFormat { /// # Examples /// /// ``` - /// use icu_locid::locale; - /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; /// use icu_datetime::date::GmtOffset; /// use icu_datetime::mock::time_zone::MockTimeZone; + /// use icu_datetime::{TimeZoneFormat, TimeZoneFormatConfig, TimeZoneFormatOptions}; + /// use icu_locid::locale; /// use icu_provider::inv::InvariantDataProvider; /// /// let provider = InvariantDataProvider; /// - /// let tzf = TimeZoneFormat::try_from_config(locale!("en"), TimeZoneFormatConfig::LocalizedGMT, &provider, &TimeZoneFormatOptions::default()) - /// .expect("Failed to create TimeZoneFormat"); + /// let tzf = TimeZoneFormat::try_from_config( + /// locale!("en"), + /// TimeZoneFormatConfig::LocalizedGMT, + /// &provider, + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create TimeZoneFormat"); /// - /// let time_zone = MockTimeZone::new( - /// GmtOffset::default(), - /// None, - /// None, - /// None, - /// ); + /// let time_zone = MockTimeZone::new(GmtOffset::default(), None, None, None); /// /// let _ = tzf.format_to_string(&time_zone); /// ``` diff --git a/components/datetime/src/zoned_datetime.rs b/components/datetime/src/zoned_datetime.rs index afe49b32f80..803a4d1c2c8 100644 --- a/components/datetime/src/zoned_datetime.rs +++ b/components/datetime/src/zoned_datetime.rs @@ -38,10 +38,10 @@ use crate::{ /// # Examples /// /// ``` -/// use icu::locid::locale; /// use icu::calendar::Gregorian; -/// use icu::datetime::{ZonedDateTimeFormat, options::length}; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; +/// use icu::datetime::{options::length, ZonedDateTimeFormat}; +/// use icu::locid::locale; /// use icu_datetime::TimeZoneFormatOptions; /// use icu_provider::inv::InvariantDataProvider; /// @@ -50,9 +50,15 @@ use crate::{ /// let plural_provider = InvariantDataProvider; /// /// let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short); -/// let zdtf = ZonedDateTimeFormat::::try_new(locale!("en"), &date_provider, &zone_provider, &plural_provider, &options.into(), &TimeZoneFormatOptions::default()) -/// .expect("Failed to create DateTimeFormat instance."); -/// +/// let zdtf = ZonedDateTimeFormat::::try_new( +/// locale!("en"), +/// &date_provider, +/// &zone_provider, +/// &plural_provider, +/// &options.into(), +/// &TimeZoneFormatOptions::default(), +/// ) +/// .expect("Failed to create DateTimeFormat instance."); /// /// let zoned_datetime: MockZonedDateTime = "2021-04-08T16:12:37.000-07:00" /// .parse() @@ -70,10 +76,10 @@ impl ZonedDateTimeFormat { /// # Examples /// /// ``` - /// use icu::locid::locale; /// use icu::calendar::Gregorian; - /// use icu::datetime::{ZonedDateTimeFormat, DateTimeFormatOptions}; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; + /// use icu::datetime::{DateTimeFormatOptions, ZonedDateTimeFormat}; + /// use icu::locid::locale; /// use icu_datetime::TimeZoneFormatOptions; /// use icu_provider::inv::InvariantDataProvider; /// @@ -83,7 +89,14 @@ impl ZonedDateTimeFormat { /// /// let options = DateTimeFormatOptions::default(); /// - /// let zdtf = ZonedDateTimeFormat::::try_new(locale!("en"), &date_provider, &zone_provider, &plural_provider, &options, &TimeZoneFormatOptions::default()); + /// let zdtf = ZonedDateTimeFormat::::try_new( + /// locale!("en"), + /// &date_provider, + /// &zone_provider, + /// &plural_provider, + /// &options, + /// &TimeZoneFormatOptions::default(), + /// ); /// /// assert_eq!(zdtf.is_ok(), true); /// ``` @@ -140,8 +153,8 @@ impl ZonedDateTimeFormat { /// /// ``` /// use icu::calendar::Gregorian; - /// use icu::datetime::ZonedDateTimeFormat; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; + /// use icu::datetime::ZonedDateTimeFormat; /// use icu_datetime::TimeZoneFormatOptions; /// use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); @@ -149,8 +162,15 @@ impl ZonedDateTimeFormat { /// # let zone_provider = InvariantDataProvider; /// # let plural_provider = InvariantDataProvider; /// # let options = icu::datetime::DateTimeFormatOptions::default(); - /// let zdtf = ZonedDateTimeFormat::::try_new(locale, &date_provider, &zone_provider, &plural_provider, &options, &TimeZoneFormatOptions::default()) - /// .expect("Failed to create ZonedDateTimeFormat instance."); + /// let zdtf = ZonedDateTimeFormat::::try_new( + /// locale, + /// &date_provider, + /// &zone_provider, + /// &plural_provider, + /// &options, + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create ZonedDateTimeFormat instance."); /// /// let zoned_datetime: MockZonedDateTime = "2021-04-08T16:12:37.000-07:00" /// .parse() @@ -179,8 +199,8 @@ impl ZonedDateTimeFormat { /// /// ``` /// use icu::calendar::Gregorian; - /// use icu::datetime::ZonedDateTimeFormat; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; + /// use icu::datetime::ZonedDateTimeFormat; /// use icu_datetime::TimeZoneFormatOptions; /// # use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); @@ -188,8 +208,15 @@ impl ZonedDateTimeFormat { /// # let zone_provider = InvariantDataProvider; /// # let plural_provider = InvariantDataProvider; /// # let options = icu::datetime::DateTimeFormatOptions::default(); - /// let zdtf = ZonedDateTimeFormat::::try_new(locale, &date_provider, &zone_provider, &plural_provider, &options.into(), &TimeZoneFormatOptions::default()) - /// .expect("Failed to create ZonedDateTimeFormat instance."); + /// let zdtf = ZonedDateTimeFormat::::try_new( + /// locale, + /// &date_provider, + /// &zone_provider, + /// &plural_provider, + /// &options.into(), + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create ZonedDateTimeFormat instance."); /// /// let zoned_datetime: MockZonedDateTime = "2021-04-08T16:12:37.000-07:00" /// .parse() @@ -216,8 +243,8 @@ impl ZonedDateTimeFormat { /// /// ``` /// use icu::calendar::Gregorian; - /// use icu::datetime::ZonedDateTimeFormat; /// use icu::datetime::mock::zoned_datetime::MockZonedDateTime; + /// use icu::datetime::ZonedDateTimeFormat; /// use icu_datetime::TimeZoneFormatOptions; /// use icu_provider::inv::InvariantDataProvider; /// # let locale = icu::locid::locale!("en"); @@ -225,8 +252,15 @@ impl ZonedDateTimeFormat { /// # let zone_provider = InvariantDataProvider; /// # let plural_provider = InvariantDataProvider; /// # let options = icu::datetime::DateTimeFormatOptions::default(); - /// let zdtf = ZonedDateTimeFormat::::try_new(locale, &date_provider, &zone_provider, &plural_provider, &options.into(), &TimeZoneFormatOptions::default()) - /// .expect("Failed to create ZonedDateTimeFormat instance."); + /// let zdtf = ZonedDateTimeFormat::::try_new( + /// locale, + /// &date_provider, + /// &zone_provider, + /// &plural_provider, + /// &options.into(), + /// &TimeZoneFormatOptions::default(), + /// ) + /// .expect("Failed to create ZonedDateTimeFormat instance."); /// /// let zoned_datetime: MockZonedDateTime = "2021-04-08T16:12:37.000-07:00" /// .parse() diff --git a/components/decimal/src/options.rs b/components/decimal/src/options.rs index 792ae04be3f..fc71d9caf34 100644 --- a/components/decimal/src/options.rs +++ b/components/decimal/src/options.rs @@ -20,9 +20,9 @@ pub struct FixedDecimalFormatOptions { /// # Examples /// /// ``` +/// use icu_decimal::options; /// use icu_decimal::FixedDecimalFormat; /// use icu_decimal::FormattedFixedDecimal; -/// use icu_decimal::options; /// use icu_locid::Locale; /// use writeable::Writeable; /// @@ -71,9 +71,9 @@ impl Default for GroupingStrategy { /// # Examples /// /// ``` +/// use icu_decimal::options; /// use icu_decimal::FixedDecimalFormat; /// use icu_decimal::FormattedFixedDecimal; -/// use icu_decimal::options; /// use icu_locid::Locale; /// use writeable::Writeable; /// diff --git a/components/icu/README.md b/components/icu/README.md index d9b428d5296..4cba85aba79 100644 --- a/components/icu/README.md +++ b/components/icu/README.md @@ -48,21 +48,24 @@ functionality are compiled. These features are: ## Example ```rust +use icu::datetime::{mock::parse_gregorian_from_str, options::length, DateTimeFormat}; use icu::locid::locale; -use icu::datetime::{DateTimeFormat, options::length, mock::parse_gregorian_from_str}; let provider = icu_testdata::get_provider(); -let options = length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium).into(); +let options = + length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium).into(); let dtf = DateTimeFormat::try_new(locale!("en"), &provider, &options) .expect("Failed to create DateTimeFormat instance."); -let date = parse_gregorian_from_str("2020-09-12T12:35:00") - .expect("Failed to parse date."); +let date = parse_gregorian_from_str("2020-09-12T12:35:00").expect("Failed to parse date."); let formatted_date = dtf.format(&date); -assert_eq!(formatted_date.to_string(), "September 12, 2020 at 12:35:00 PM"); +assert_eq!( + formatted_date.to_string(), + "September 12, 2020 at 12:35:00 PM" +); ``` [`DataProvider`]: ../icu_provider/prelude/trait.DataProvider.html diff --git a/components/icu/src/lib.rs b/components/icu/src/lib.rs index d5a2214851f..4127e594111 100644 --- a/components/icu/src/lib.rs +++ b/components/icu/src/lib.rs @@ -50,21 +50,24 @@ //! # Example //! //! ``` +//! use icu::datetime::{mock::parse_gregorian_from_str, options::length, DateTimeFormat}; //! use icu::locid::locale; -//! use icu::datetime::{DateTimeFormat, options::length, mock::parse_gregorian_from_str}; //! //! let provider = icu_testdata::get_provider(); //! -//! let options = length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium).into(); +//! let options = +//! length::Bag::from_date_time_style(length::Date::Long, length::Time::Medium).into(); //! //! let dtf = DateTimeFormat::try_new(locale!("en"), &provider, &options) //! .expect("Failed to create DateTimeFormat instance."); //! -//! let date = parse_gregorian_from_str("2020-09-12T12:35:00") -//! .expect("Failed to parse date."); +//! let date = parse_gregorian_from_str("2020-09-12T12:35:00").expect("Failed to parse date."); //! //! let formatted_date = dtf.format(&date); -//! assert_eq!(formatted_date.to_string(), "September 12, 2020 at 12:35:00 PM"); +//! assert_eq!( +//! formatted_date.to_string(), +//! "September 12, 2020 at 12:35:00 PM" +//! ); //! ``` //! //! [`DataProvider`]: ../icu_provider/prelude/trait.DataProvider.html @@ -111,17 +114,17 @@ pub mod datetime { //! # Examples //! //! ``` + //! use icu::datetime::{mock::parse_gregorian_from_str, options::length, DateTimeFormat}; //! use icu::locid::locale; - //! use icu::datetime::{DateTimeFormat, options::length, mock::parse_gregorian_from_str}; //! //! let provider = icu_testdata::get_provider(); //! - //! let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); + //! let options = + //! length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short).into(); //! let dtf = DateTimeFormat::try_new(locale!("en"), &provider, &options) //! .expect("Failed to create DateTimeFormat instance."); //! - //! let date = parse_gregorian_from_str("2020-09-12T12:35:00") - //! .expect("Failed to parse date."); + //! let date = parse_gregorian_from_str("2020-09-12T12:35:00").expect("Failed to parse date."); //! //! let formatted_date = dtf.format(&date); //! assert_eq!(formatted_date.to_string(), "Sep 12, 2020, 12:35 PM"); @@ -195,16 +198,13 @@ pub mod locale_canonicalizer { //! use icu_locid::Locale; //! //! let provider = icu_testdata::get_provider(); - //! let lc = LocaleCanonicalizer::new(&provider) - //! .expect("create failed"); + //! let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); //! - //! let mut locale : Locale = "zh-CN".parse() - //! .expect("parse failed"); + //! let mut locale: Locale = "zh-CN".parse().expect("parse failed"); //! assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified); //! assert_eq!(locale.to_string(), "zh-Hans-CN"); //! - //! let mut locale : Locale = "zh-Hant-TW".parse() - //! .expect("parse failed"); + //! let mut locale: Locale = "zh-Hant-TW".parse().expect("parse failed"); //! assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified); //! assert_eq!(locale.to_string(), "zh-Hant-TW"); //! ``` @@ -214,16 +214,13 @@ pub mod locale_canonicalizer { //! use icu_locid::Locale; //! //! let provider = icu_testdata::get_provider(); - //! let lc = LocaleCanonicalizer::new(&provider) - //! .expect("create failed"); + //! let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); //! - //! let mut locale : Locale = "zh-Hans-CN".parse() - //! .expect("parse failed"); + //! let mut locale: Locale = "zh-Hans-CN".parse().expect("parse failed"); //! assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified); //! assert_eq!(locale.to_string(), "zh"); //! - //! let mut locale : Locale = "zh".parse() - //! .expect("parse failed"); + //! let mut locale: Locale = "zh".parse().expect("parse failed"); //! assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified); //! assert_eq!(locale.to_string(), "zh"); //! ``` @@ -301,7 +298,7 @@ pub mod plurals { //! //! ``` //! use icu::locid::locale; - //! use icu::plurals::{PluralRules, PluralRuleType, PluralCategory}; + //! use icu::plurals::{PluralCategory, PluralRuleType, PluralRules}; //! //! let provider = icu_testdata::get_provider(); //! @@ -364,14 +361,12 @@ pub mod properties { //! //! // A binary property as a `UnicodeSet` //! - //! let payload = - //! sets::get_emoji(&provider) - //! .expect("The data should be valid"); + //! let payload = sets::get_emoji(&provider).expect("The data should be valid"); //! let data_struct = payload.get(); //! let emoji = &data_struct.inv_list; //! - //! assert!(emoji.contains('🎃')); // U+1F383 JACK-O-LANTERN - //! assert!(!emoji.contains('木')); // U+6728 + //! assert!(emoji.contains('🎃')); // U+1F383 JACK-O-LANTERN + //! assert!(!emoji.contains('木')); // U+6728 //! //! // An individual enumerated property value as a `UnicodeSet` //! @@ -391,14 +386,12 @@ pub mod properties { //! //! let provider = icu_testdata::get_provider(); //! - //! let payload = - //! maps::get_script(&provider) - //! .expect("The data should be valid"); + //! let payload = maps::get_script(&provider).expect("The data should be valid"); //! let data_struct = payload.get(); //! let script = &data_struct.code_point_trie; //! - //! assert_eq!(script.get('🎃' as u32), Script::Common); // U+1F383 JACK-O-LANTERN - //! assert_eq!(script.get('木' as u32), Script::Han); // U+6728 + //! assert_eq!(script.get('🎃' as u32), Script::Common); // U+1F383 JACK-O-LANTERN + //! assert_eq!(script.get('木' as u32), Script::Han); // U+6728 //! ``` //! //! ## Property data for `Script` and `Script_Extensions` @@ -408,9 +401,7 @@ pub mod properties { //! //! let provider = icu_testdata::get_provider(); //! - //! let payload = - //! script::get_script_with_extensions(&provider) - //! .expect("The data should be valid"); + //! let payload = script::get_script_with_extensions(&provider).expect("The data should be valid"); //! let data_struct = payload.get(); //! let swe = &data_struct.data; //! @@ -421,14 +412,24 @@ pub mod properties { //! // get the `Script_Extensions` property value //! assert_eq!( //! swe.get_script_extensions_val(0x0640) // U+0640 ARABIC TATWEEL - //! .iter().collect::>(), - //! vec![Script::Arabic, Script::Syriac, Script::Mandaic, Script::Manichaean, - //! Script::PsalterPahlavi, Script::Adlam, Script::HanifiRohingya, Script::Sogdian, - //! Script::OldUyghur] + //! .iter() + //! .collect::>(), + //! vec![ + //! Script::Arabic, + //! Script::Syriac, + //! Script::Mandaic, + //! Script::Manichaean, + //! Script::PsalterPahlavi, + //! Script::Adlam, + //! Script::HanifiRohingya, + //! Script::Sogdian, + //! Script::OldUyghur + //! ] //! ); //! assert_eq!( //! swe.get_script_extensions_val('௫' as u32) // U+0BEB TAMIL DIGIT FIVE - //! .iter().collect::>(), + //! .iter() + //! .collect::>(), //! vec![Script::Tamil, Script::Grantha] //! ); //! @@ -472,14 +473,16 @@ pub mod list { //! .expect("Data should load successfully"); //! //! assert_eq!( - //! list_formatter.format(["España", "Suiza"].iter()) + //! list_formatter + //! .format(["España", "Suiza"].iter()) //! .write_to_string(), //! "España y Suiza" //! ); //! //! // The Spanish 'y' sometimes becomes an 'e': //! assert_eq!( - //! list_formatter.format(["España", "Suiza", "Italia"].iter()) + //! list_formatter + //! .format(["España", "Suiza", "Italia"].iter()) //! .write_to_string(), //! "España, Suiza e Italia" //! ); @@ -489,7 +492,7 @@ pub mod list { //! list_formatter.format(1..=10).write_to_string(), //! "1, 2, 3, 4, 5, 6, 7, 8, 9 y 10" //! ); - //!``` + //! ``` //! //! [`ListFormatter`]: ListFormatter diff --git a/components/list/README.md b/components/list/README.md index cb18ce8d316..564f363c65f 100644 --- a/components/list/README.md +++ b/components/list/README.md @@ -20,14 +20,16 @@ let list_formatter = ListFormatter::try_new_and( .expect("Data should load successfully"); assert_eq!( - list_formatter.format(["España", "Suiza"].iter()) + list_formatter + .format(["España", "Suiza"].iter()) .write_to_string(), "España y Suiza" ); // The Spanish 'y' sometimes becomes an 'e': assert_eq!( - list_formatter.format(["España", "Suiza", "Italia"].iter()) + list_formatter + .format(["España", "Suiza", "Italia"].iter()) .write_to_string(), "España, Suiza e Italia" ); diff --git a/components/list/src/lib.rs b/components/list/src/lib.rs index 7dc3eea4833..d9e06ec08b3 100644 --- a/components/list/src/lib.rs +++ b/components/list/src/lib.rs @@ -24,14 +24,16 @@ //! .expect("Data should load successfully"); //! //! assert_eq!( -//! list_formatter.format(["España", "Suiza"].iter()) +//! list_formatter +//! .format(["España", "Suiza"].iter()) //! .write_to_string(), //! "España y Suiza" //! ); //! //! // The Spanish 'y' sometimes becomes an 'e': //! assert_eq!( -//! list_formatter.format(["España", "Suiza", "Italia"].iter()) +//! list_formatter +//! .format(["España", "Suiza", "Italia"].iter()) //! .write_to_string(), //! "España, Suiza e Italia" //! ); @@ -41,7 +43,7 @@ //! list_formatter.format(1..=10).write_to_string(), //! "1, 2, 3, 4, 5, 6, 7, 8, 9 y 10" //! ); -//!``` +//! ``` //! //! [`ListFormatter`]: ListFormatter diff --git a/components/locale_canonicalizer/README.md b/components/locale_canonicalizer/README.md index ec41c248ba0..26a39dfff00 100644 --- a/components/locale_canonicalizer/README.md +++ b/components/locale_canonicalizer/README.md @@ -24,12 +24,15 @@ use icu_locale_canonicalizer::{CanonicalizationResult, LocaleCanonicalizer}; use icu_locid::Locale; let provider = icu_testdata::get_provider(); -let lc = LocaleCanonicalizer::new(&provider) - .expect("create failed"); +let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); -let mut locale : Locale = "ja-Latn-fonipa-hepburn-heploc".parse() +let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc" + .parse() .expect("parse failed"); -assert_eq!(lc.canonicalize(&mut locale), CanonicalizationResult::Modified); +assert_eq!( + lc.canonicalize(&mut locale), + CanonicalizationResult::Modified +); assert_eq!(locale.to_string(), "ja-Latn-alalc97-fonipa"); ``` @@ -38,16 +41,13 @@ use icu_locale_canonicalizer::{CanonicalizationResult, LocaleCanonicalizer}; use icu_locid::Locale; let provider = icu_testdata::get_provider(); -let lc = LocaleCanonicalizer::new(&provider) - .expect("create failed"); +let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); -let mut locale : Locale = "zh-CN".parse() - .expect("parse failed"); +let mut locale: Locale = "zh-CN".parse().expect("parse failed"); assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified); assert_eq!(locale.to_string(), "zh-Hans-CN"); -let mut locale : Locale = "zh-Hant-TW".parse() - .expect("parse failed"); +let mut locale: Locale = "zh-Hant-TW".parse().expect("parse failed"); assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified); assert_eq!(locale.to_string(), "zh-Hant-TW"); ``` @@ -57,16 +57,13 @@ use icu_locale_canonicalizer::{CanonicalizationResult, LocaleCanonicalizer}; use icu_locid::Locale; let provider = icu_testdata::get_provider(); -let lc = LocaleCanonicalizer::new(&provider) - .expect("create failed"); +let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); -let mut locale : Locale = "zh-Hans-CN".parse() - .expect("parse failed"); +let mut locale: Locale = "zh-Hans-CN".parse().expect("parse failed"); assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified); assert_eq!(locale.to_string(), "zh"); -let mut locale : Locale = "zh".parse() - .expect("parse failed"); +let mut locale: Locale = "zh".parse().expect("parse failed"); assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified); assert_eq!(locale.to_string(), "zh"); ``` diff --git a/components/locale_canonicalizer/src/lib.rs b/components/locale_canonicalizer/src/lib.rs index 96b359adcef..290252a3707 100644 --- a/components/locale_canonicalizer/src/lib.rs +++ b/components/locale_canonicalizer/src/lib.rs @@ -26,12 +26,15 @@ //! use icu_locid::Locale; //! //! let provider = icu_testdata::get_provider(); -//! let lc = LocaleCanonicalizer::new(&provider) -//! .expect("create failed"); +//! let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); //! -//! let mut locale : Locale = "ja-Latn-fonipa-hepburn-heploc".parse() +//! let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc" +//! .parse() //! .expect("parse failed"); -//! assert_eq!(lc.canonicalize(&mut locale), CanonicalizationResult::Modified); +//! assert_eq!( +//! lc.canonicalize(&mut locale), +//! CanonicalizationResult::Modified +//! ); //! assert_eq!(locale.to_string(), "ja-Latn-alalc97-fonipa"); //! ``` //! @@ -40,16 +43,13 @@ //! use icu_locid::Locale; //! //! let provider = icu_testdata::get_provider(); -//! let lc = LocaleCanonicalizer::new(&provider) -//! .expect("create failed"); +//! let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); //! -//! let mut locale : Locale = "zh-CN".parse() -//! .expect("parse failed"); +//! let mut locale: Locale = "zh-CN".parse().expect("parse failed"); //! assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified); //! assert_eq!(locale.to_string(), "zh-Hans-CN"); //! -//! let mut locale : Locale = "zh-Hant-TW".parse() -//! .expect("parse failed"); +//! let mut locale: Locale = "zh-Hant-TW".parse().expect("parse failed"); //! assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified); //! assert_eq!(locale.to_string(), "zh-Hant-TW"); //! ``` @@ -59,16 +59,13 @@ //! use icu_locid::Locale; //! //! let provider = icu_testdata::get_provider(); -//! let lc = LocaleCanonicalizer::new(&provider) -//! .expect("create failed"); +//! let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); //! -//! let mut locale : Locale = "zh-Hans-CN".parse() -//! .expect("parse failed"); +//! let mut locale: Locale = "zh-Hans-CN".parse().expect("parse failed"); //! assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified); //! assert_eq!(locale.to_string(), "zh"); //! -//! let mut locale : Locale = "zh".parse() -//! .expect("parse failed"); +//! let mut locale: Locale = "zh".parse().expect("parse failed"); //! assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified); //! assert_eq!(locale.to_string(), "zh"); //! ``` diff --git a/components/locale_canonicalizer/src/locale_canonicalizer.rs b/components/locale_canonicalizer/src/locale_canonicalizer.rs index 46dd24296e4..0ce2866086d 100644 --- a/components/locale_canonicalizer/src/locale_canonicalizer.rs +++ b/components/locale_canonicalizer/src/locale_canonicalizer.rs @@ -54,12 +54,15 @@ pub enum CanonicalizationResult { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); -/// let lc = LocaleCanonicalizer::new(&provider) -/// .expect("create failed"); +/// let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); /// -/// let mut locale : Locale = "ja-Latn-fonipa-hepburn-heploc".parse() +/// let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc" +/// .parse() /// .expect("parse failed"); -/// assert_eq!(lc.canonicalize(&mut locale), CanonicalizationResult::Modified); +/// assert_eq!( +/// lc.canonicalize(&mut locale), +/// CanonicalizationResult::Modified +/// ); /// assert_eq!(locale.to_string(), "ja-Latn-alalc97-fonipa"); /// ``` /// @@ -68,16 +71,13 @@ pub enum CanonicalizationResult { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); -/// let lc = LocaleCanonicalizer::new(&provider) -/// .expect("create failed"); +/// let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); /// -/// let mut locale : Locale = "zh-CN".parse() -/// .expect("parse failed"); +/// let mut locale: Locale = "zh-CN".parse().expect("parse failed"); /// assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified); /// assert_eq!(locale.to_string(), "zh-Hans-CN"); /// -/// let mut locale : Locale = "zh-Hant-TW".parse() -/// .expect("parse failed"); +/// let mut locale: Locale = "zh-Hant-TW".parse().expect("parse failed"); /// assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified); /// assert_eq!(locale.to_string(), "zh-Hant-TW"); /// ``` @@ -87,16 +87,13 @@ pub enum CanonicalizationResult { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); -/// let lc = LocaleCanonicalizer::new(&provider) -/// .expect("create failed"); +/// let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); /// -/// let mut locale : Locale = "zh-Hans-CN".parse() -/// .expect("parse failed"); +/// let mut locale: Locale = "zh-Hans-CN".parse().expect("parse failed"); /// assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified); /// assert_eq!(locale.to_string(), "zh"); /// -/// let mut locale : Locale = "zh".parse() -/// .expect("parse failed"); +/// let mut locale: Locale = "zh".parse().expect("parse failed"); /// assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified); /// assert_eq!(locale.to_string(), "zh"); /// ``` @@ -342,15 +339,17 @@ impl LocaleCanonicalizer { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); - /// let lc = LocaleCanonicalizer::new(&provider) - /// .expect("create failed"); + /// let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); /// - /// let mut locale : Locale = "ja-Latn-fonipa-hepburn-heploc".parse() + /// let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc" + /// .parse() /// .expect("parse failed"); - /// assert_eq!(lc.canonicalize(&mut locale), CanonicalizationResult::Modified); + /// assert_eq!( + /// lc.canonicalize(&mut locale), + /// CanonicalizationResult::Modified + /// ); /// assert_eq!(locale.to_string(), "ja-Latn-alalc97-fonipa"); /// ``` - /// pub fn canonicalize(&self, locale: &mut Locale) -> CanonicalizationResult { let mut result = CanonicalizationResult::Unmodified; @@ -582,16 +581,13 @@ impl LocaleCanonicalizer { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); - /// let lc = LocaleCanonicalizer::new(&provider) - /// .expect("create failed"); + /// let lc = LocaleCanonicalizer::new(&provider).expect("create failed"); /// - /// let mut locale : Locale = "zh-CN".parse() - /// .expect("parse failed"); + /// let mut locale: Locale = "zh-CN".parse().expect("parse failed"); /// assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Modified); /// assert_eq!(locale.to_string(), "zh-Hans-CN"); /// - /// let mut locale : Locale = "zh-Hant-TW".parse() - /// .expect("parse failed"); + /// let mut locale: Locale = "zh-Hant-TW".parse().expect("parse failed"); /// assert_eq!(lc.maximize(&mut locale), CanonicalizationResult::Unmodified); /// assert_eq!(locale.to_string(), "zh-Hant-TW"); /// ``` @@ -678,16 +674,13 @@ impl LocaleCanonicalizer { /// use icu_locid::Locale; /// /// let provider = icu_testdata::get_provider(); - /// let lc = LocaleCanonicalizer::new(&provider) - /// .expect("creation failed"); + /// let lc = LocaleCanonicalizer::new(&provider).expect("creation failed"); /// - /// let mut locale : Locale = "zh-Hans-CN".parse() - /// .expect("parse failed"); + /// let mut locale: Locale = "zh-Hans-CN".parse().expect("parse failed"); /// assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Modified); /// assert_eq!(locale.to_string(), "zh"); /// - /// let mut locale : Locale = "zh".parse() - /// .expect("parse failed"); + /// let mut locale: Locale = "zh".parse().expect("parse failed"); /// assert_eq!(lc.minimize(&mut locale), CanonicalizationResult::Unmodified); /// assert_eq!(locale.to_string(), "zh"); /// ``` diff --git a/components/locid/README.md b/components/locid/README.md index a625a22f864..a95165fe2ce 100644 --- a/components/locid/README.md +++ b/components/locid/README.md @@ -20,16 +20,13 @@ If in doubt, use [`Locale`]. ## Examples ```rust -use icu::locid::Locale; use icu::locid::subtags::{Language, Region}; +use icu::locid::Locale; -let mut loc: Locale = "en-US".parse() - .expect("Parsing failed."); +let mut loc: Locale = "en-US".parse().expect("Parsing failed."); -let lang: Language = "en".parse() - .expect("Parsing failed."); -let region: Region = "US".parse() - .expect("Parsing failed."); +let lang: Language = "en".parse().expect("Parsing failed."); +let region: Region = "US".parse().expect("Parsing failed."); assert_eq!(loc.id.language, lang); assert_eq!(loc.id.script, None); @@ -45,7 +42,7 @@ assert_eq!(loc.to_string(), "en-GB"); ### Macros ```rust -use icu::locid::{language, region, langid}; +use icu::locid::{langid, language, region}; let lid = langid!("EN_US"); diff --git a/components/locid/src/extensions/mod.rs b/components/locid/src/extensions/mod.rs index 5ef36db67d3..b54e1c55c88 100644 --- a/components/locid/src/extensions/mod.rs +++ b/components/locid/src/extensions/mod.rs @@ -20,10 +20,11 @@ //! # Examples //! //! ``` -//! use icu::locid::Locale; //! use icu::locid::extensions::unicode::{Key, Value}; +//! use icu::locid::Locale; //! -//! let loc: Locale = "en-US-u-ca-buddhist-t-en-US-h0-hybrid-x-foo".parse() +//! let loc: Locale = "en-US-u-ca-buddhist-t-en-US-h0-hybrid-x-foo" +//! .parse() //! .expect("Failed to parse."); //! //! assert_eq!(loc.id.language, "en"); @@ -31,11 +32,9 @@ //! assert_eq!(loc.id.region, Some("US".parse().unwrap())); //! assert_eq!(loc.id.variants.len(), 0); //! -//! //! let key: Key = "ca".parse().expect("Parsing key failed."); //! let value: Value = "buddhist".parse().expect("Parsing value failed."); -//! assert_eq!(loc.extensions.unicode.keywords.get(&key), -//! Some(&value)); +//! assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value)); //! ``` //! //! [`LanguageIdentifier`]: super::LanguageIdentifier @@ -125,8 +124,7 @@ impl Extensions { /// ``` /// use icu::locid::Locale; /// - /// let loc: Locale = "en-US-u-foo".parse() - /// .expect("Parsing failed."); + /// let loc: Locale = "en-US-u-foo".parse().expect("Parsing failed."); /// /// assert_eq!(loc.extensions.is_empty(), false); /// ``` @@ -142,21 +140,22 @@ impl Extensions { /// # Examples /// /// ``` - /// use std::str::FromStr; - /// use icu::locid::Locale; /// use icu::locid::extensions::ExtensionType; + /// use icu::locid::Locale; + /// use std::str::FromStr; /// /// let loc: Locale = "und-a-hello-t-mul-u-world-z-zzz-x-extra".parse().unwrap(); /// /// let mut only_unicode = loc.clone(); - /// only_unicode.extensions.retain_by_type(|t| t == ExtensionType::Unicode); + /// only_unicode + /// .extensions + /// .retain_by_type(|t| t == ExtensionType::Unicode); /// assert_eq!(only_unicode, "und-u-world"); /// /// let mut only_t_z = loc.clone(); - /// only_t_z.extensions.retain_by_type(|t| { - /// t == ExtensionType::Transform - /// || t == ExtensionType::Other(b'z') - /// }); + /// only_t_z + /// .extensions + /// .retain_by_type(|t| t == ExtensionType::Transform || t == ExtensionType::Other(b'z')); /// assert_eq!(only_t_z, "und-t-mul-z-zzz"); /// ``` pub fn retain_by_type(&mut self, mut predicate: F) diff --git a/components/locid/src/extensions/other/key.rs b/components/locid/src/extensions/other/key.rs index b71827fd5aa..a177c964537 100644 --- a/components/locid/src/extensions/other/key.rs +++ b/components/locid/src/extensions/other/key.rs @@ -18,8 +18,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::other::Key; /// -/// let key1: Key = "Foo".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "Foo".parse().expect("Failed to parse a Key."); /// /// assert_eq!(key1.as_str(), "foo"); /// ``` @@ -42,8 +41,7 @@ impl Key { /// ``` /// use icu::locid::extensions::other::Key; /// - /// let key = Key::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(key.as_str(), "foobar"); /// ``` @@ -69,8 +67,7 @@ impl Key { /// ``` /// use icu::locid::extensions::other::Key; /// - /// let key = Key::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(key.as_str(), "foobar"); /// ``` diff --git a/components/locid/src/extensions/other/mod.rs b/components/locid/src/extensions/other/mod.rs index 6cc89123d91..cafdbf2f560 100644 --- a/components/locid/src/extensions/other/mod.rs +++ b/components/locid/src/extensions/other/mod.rs @@ -13,11 +13,10 @@ //! # Examples //! //! ``` -//! use icu::locid::Locale; //! use icu::locid::extensions::other::Other; +//! use icu::locid::Locale; //! -//! let mut loc: Locale = "en-US-a-foo-faa".parse() -//! .expect("Parsing failed."); +//! let mut loc: Locale = "en-US-a-foo-faa".parse().expect("Parsing failed."); //! ``` //! //! [`Keys`]: Key @@ -38,12 +37,10 @@ pub use key::Key; /// # Examples /// /// ``` -/// use icu::locid::extensions::other::{Other, Key}; +/// use icu::locid::extensions::other::{Key, Other}; /// -/// let key1: Key = "foo".parse() -/// .expect("Failed to parse a Key."); -/// let key2: Key = "bar".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "foo".parse().expect("Failed to parse a Key."); +/// let key2: Key = "bar".parse().expect("Failed to parse a Key."); /// /// let other = Other::from_vec_unchecked(b'a', vec![key1, key2]); /// assert_eq!(&other.to_string(), "-a-foo-bar"); @@ -64,12 +61,10 @@ impl Other { /// # Examples /// /// ``` - /// use icu::locid::extensions::other::{Other, Key}; + /// use icu::locid::extensions::other::{Key, Other}; /// - /// let key1: Key = "foo".parse() - /// .expect("Failed to parse a Key."); - /// let key2: Key = "bar".parse() - /// .expect("Failed to parse a Key."); + /// let key1: Key = "foo".parse().expect("Failed to parse a Key."); + /// let key2: Key = "bar".parse().expect("Failed to parse a Key."); /// /// let other = Other::from_vec_unchecked(b'a', vec![key1, key2]); /// assert_eq!(&other.to_string(), "-a-foo-bar"); @@ -101,8 +96,8 @@ impl Other { /// # Examples /// /// ``` - /// use std::str::FromStr; /// use icu::locid::Locale; + /// use std::str::FromStr; /// /// let loc: Locale = "und-a-hello-world".parse().unwrap(); /// let other_ext = &loc.extensions.other[0]; @@ -117,8 +112,8 @@ impl Other { /// # Examples /// /// ``` - /// use std::str::FromStr; /// use icu::locid::Locale; + /// use std::str::FromStr; /// /// let loc: Locale = "und-a-hello-world".parse().unwrap(); /// let other_ext = &loc.extensions.other[0]; diff --git a/components/locid/src/extensions/private/key.rs b/components/locid/src/extensions/private/key.rs index b72482cabdd..caa7dc1d806 100644 --- a/components/locid/src/extensions/private/key.rs +++ b/components/locid/src/extensions/private/key.rs @@ -18,8 +18,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::private::Key; /// -/// let key1: Key = "Foo".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "Foo".parse().expect("Failed to parse a Key."); /// /// assert_eq!(key1.as_str(), "foo"); /// ``` @@ -37,8 +36,7 @@ impl Key { /// ``` /// use icu::locid::extensions::private::Key; /// - /// let key = Key::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(key.as_str(), "foobar"); /// ``` @@ -64,8 +62,7 @@ impl Key { /// ``` /// use icu::locid::extensions::private::Key; /// - /// let key = Key::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(key.as_str(), "foobar"); /// ``` diff --git a/components/locid/src/extensions/private/mod.rs b/components/locid/src/extensions/private/mod.rs index bba9051fc10..a53722b77de 100644 --- a/components/locid/src/extensions/private/mod.rs +++ b/components/locid/src/extensions/private/mod.rs @@ -13,14 +13,12 @@ //! # Examples //! //! ``` +//! use icu::locid::extensions::private::{Key, Private}; //! use icu::locid::Locale; -//! use icu::locid::extensions::private::{Private, Key}; //! -//! let mut loc: Locale = "en-US-x-foo-faa".parse() -//! .expect("Parsing failed."); +//! let mut loc: Locale = "en-US-x-foo-faa".parse().expect("Parsing failed."); //! -//! let key: Key = "foo".parse() -//! .expect("Parsing key failed."); +//! let key: Key = "foo".parse().expect("Parsing key failed."); //! assert_eq!(loc.extensions.private.contains(&key), true); //! assert_eq!(loc.extensions.private.iter().next(), Some(&key)); //! loc.extensions.private.clear(); @@ -48,12 +46,10 @@ use crate::parser::SubtagIterator; /// # Examples /// /// ``` -/// use icu::locid::extensions::private::{Private, Key}; +/// use icu::locid::extensions::private::{Key, Private}; /// -/// let key1: Key = "foo".parse() -/// .expect("Failed to parse a Key."); -/// let key2: Key = "bar".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "foo".parse().expect("Failed to parse a Key."); +/// let key2: Key = "bar".parse().expect("Failed to parse a Key."); /// /// let private = Private::from_vec_unchecked(vec![key1, key2]); /// assert_eq!(&private.to_string(), "-x-foo-bar"); @@ -84,12 +80,10 @@ impl Private { /// # Examples /// /// ``` - /// use icu::locid::extensions::private::{Private, Key}; + /// use icu::locid::extensions::private::{Key, Private}; /// - /// let key1: Key = "foo".parse() - /// .expect("Failed to parse a Key."); - /// let key2: Key = "bar".parse() - /// .expect("Failed to parse a Key."); + /// let key1: Key = "foo".parse().expect("Failed to parse a Key."); + /// let key2: Key = "bar".parse().expect("Failed to parse a Key."); /// /// let private = Private::from_vec_unchecked(vec![key1, key2]); /// assert_eq!(&private.to_string(), "-x-foo-bar"); @@ -103,12 +97,10 @@ impl Private { /// # Examples /// /// ``` - /// use icu::locid::extensions::private::{Private, Key}; + /// use icu::locid::extensions::private::{Key, Private}; /// - /// let key1: Key = "foo".parse() - /// .expect("Failed to parse a Key."); - /// let key2: Key = "bar".parse() - /// .expect("Failed to parse a Key."); + /// let key1: Key = "foo".parse().expect("Failed to parse a Key."); + /// let key2: Key = "bar".parse().expect("Failed to parse a Key."); /// let mut private = Private::from_vec_unchecked(vec![key1, key2]); /// /// assert_eq!(&private.to_string(), "-x-foo-bar"); diff --git a/components/locid/src/extensions/transform/fields.rs b/components/locid/src/extensions/transform/fields.rs index d80ebbe94cf..d0e372a72a0 100644 --- a/components/locid/src/extensions/transform/fields.rs +++ b/components/locid/src/extensions/transform/fields.rs @@ -26,10 +26,8 @@ use super::Value; /// ``` /// use icu::locid::extensions::transform::{Fields, Key, Value}; /// -/// let key: Key = "h0".parse() -/// .expect("Failed to parse a Key."); -/// let value: Value = "hybrid".parse() -/// .expect("Failed to parse a Value."); +/// let key: Key = "h0".parse().expect("Failed to parse a Key."); +/// let value: Value = "hybrid".parse().expect("Failed to parse a Value."); /// let fields: Fields = vec![(key, value)].into_iter().collect(); /// /// assert_eq!(&fields.to_string(), "h0-hybrid"); @@ -57,8 +55,8 @@ impl Fields { /// # Examples /// /// ``` - /// use icu::locid::Locale; /// use icu::locid::extensions::transform::Fields; + /// use icu::locid::Locale; /// /// let loc1 = Locale::from_bytes(b"und-t-h0-hybrid").unwrap(); /// let loc2 = Locale::from_bytes(b"und-u-ca-buddhist").unwrap(); @@ -77,10 +75,8 @@ impl Fields { /// ``` /// use icu::locid::extensions::transform::{Fields, Key, Value}; /// - /// let key: Key = "h0".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "hybrid".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "h0".parse().expect("Failed to parse a Key."); + /// let value: Value = "hybrid".parse().expect("Failed to parse a Value."); /// let mut fields: Fields = vec![(key, value)].into_iter().collect(); /// /// assert_eq!(&fields.to_string(), "h0-hybrid"); @@ -101,14 +97,11 @@ impl Fields { /// ``` /// use icu::locid::extensions::transform::{Fields, Key, Value}; /// - /// let key: Key = "h0".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "hybrid".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "h0".parse().expect("Failed to parse a Key."); + /// let value: Value = "hybrid".parse().expect("Failed to parse a Value."); /// let mut fields: Fields = vec![(key, value)].into_iter().collect(); /// - /// let key: Key = "h0".parse() - /// .expect("Failed to parse a Key."); + /// let key: Key = "h0".parse().expect("Failed to parse a Key."); /// assert!(&fields.contains_key(&key)); /// ``` pub fn contains_key(&self, key: &Q) -> bool @@ -127,14 +120,11 @@ impl Fields { /// ``` /// use icu::locid::extensions::transform::{Fields, Key, Value}; /// - /// let key: Key = "h0".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "hybrid".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "h0".parse().expect("Failed to parse a Key."); + /// let value: Value = "hybrid".parse().expect("Failed to parse a Value."); /// let mut fields: Fields = vec![(key, value)].into_iter().collect(); /// - /// let key: Key = "h0".parse() - /// .expect("Failed to parse a Key."); + /// let key: Key = "h0".parse().expect("Failed to parse a Key."); /// assert_eq!( /// fields.get(&key).map(|v| v.to_string()), /// Some("hybrid".to_string()) @@ -153,23 +143,21 @@ impl Fields { /// # Examples /// /// ``` - /// use std::str::FromStr; - /// use std::string::ToString; - /// use icu::locid::transform_ext_key; - /// use icu::locid::Locale; /// use icu::locid::extensions::transform::Key; /// use icu::locid::extensions::transform::Value; + /// use icu::locid::transform_ext_key; + /// use icu::locid::Locale; + /// use std::str::FromStr; + /// use std::string::ToString; /// /// const D0_KEY: Key = transform_ext_key!("d0"); /// let lower = Value::from_str("lower").expect("valid extension subtag"); /// let casefold = Value::from_str("casefold").expect("valid extension subtag"); /// - /// let mut loc: Locale = "en-t-hi-d0-casefold".parse() + /// let mut loc: Locale = "en-t-hi-d0-casefold" + /// .parse() /// .expect("valid BCP-47 identifier"); - /// let old_value = loc.extensions.transform.fields.set( - /// D0_KEY, - /// lower - /// ); + /// let old_value = loc.extensions.transform.fields.set(D0_KEY, lower); /// /// assert_eq!(old_value, Some(casefold)); /// assert_eq!(loc, "en-t-hi-d0-lower"); diff --git a/components/locid/src/extensions/transform/key.rs b/components/locid/src/extensions/transform/key.rs index db5c655ded2..6837b000559 100644 --- a/components/locid/src/extensions/transform/key.rs +++ b/components/locid/src/extensions/transform/key.rs @@ -17,8 +17,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::transform::Key; /// -/// let key1: Key = "k0".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "k0".parse().expect("Failed to parse a Key."); /// /// assert_eq!(key1.as_str(), "k0"); /// ``` @@ -36,8 +35,7 @@ impl Key { /// ``` /// use icu::locid::extensions::transform::Key; /// - /// let key = Key::from_bytes(b"i0") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"i0").expect("Parsing failed."); /// /// assert_eq!(key, "i0"); /// ``` @@ -61,8 +59,7 @@ impl Key { /// ``` /// use icu::locid::extensions::transform::Key; /// - /// let key: Key = "s0".parse() - /// .expect("Parsing failed."); + /// let key: Key = "s0".parse().expect("Parsing failed."); /// /// assert_eq!(key.as_str(), "s0"); /// ``` diff --git a/components/locid/src/extensions/transform/mod.rs b/components/locid/src/extensions/transform/mod.rs index 21224bb2698..7e9636a6c12 100644 --- a/components/locid/src/extensions/transform/mod.rs +++ b/components/locid/src/extensions/transform/mod.rs @@ -12,19 +12,15 @@ //! # Examples //! //! ``` +//! use icu::locid::extensions::transform::{Fields, Key, Transform, Value}; //! use icu::locid::{LanguageIdentifier, Locale}; -//! use icu::locid::extensions::transform::{Transform, Fields, Key, Value}; //! -//! let mut loc: Locale = "en-US-t-es-AR-h0-hybrid".parse() -//! .expect("Parsing failed."); +//! let mut loc: Locale = "en-US-t-es-AR-h0-hybrid".parse().expect("Parsing failed."); //! -//! let lang: LanguageIdentifier = "es-AR".parse() -//! .expect("Parsing LanguageIdentifier failed."); +//! let lang: LanguageIdentifier = "es-AR".parse().expect("Parsing LanguageIdentifier failed."); //! -//! let key: Key = "h0".parse() -//! .expect("Parsing key failed."); -//! let value: Value = "hybrid".parse() -//! .expect("Parsing value failed."); +//! let key: Key = "h0".parse().expect("Parsing key failed."); +//! let value: Value = "hybrid".parse().expect("Parsing value failed."); //! //! assert_eq!(loc.extensions.transform.lang, Some(lang)); //! assert!(loc.extensions.transform.fields.contains_key(&key)); @@ -57,22 +53,17 @@ use litemap::LiteMap; /// # Examples /// /// ``` -/// use icu::locid::{Locale, LanguageIdentifier}; /// use icu::locid::extensions::transform::{Key, Value}; +/// use icu::locid::{LanguageIdentifier, Locale}; /// -/// let mut loc: Locale = "de-t-en-US-h0-hybrid".parse() -/// .expect("Parsing failed."); +/// let mut loc: Locale = "de-t-en-US-h0-hybrid".parse().expect("Parsing failed."); /// -/// let en_us: LanguageIdentifier = "en-US".parse() -/// .expect("Parsing failed."); +/// let en_us: LanguageIdentifier = "en-US".parse().expect("Parsing failed."); /// /// assert_eq!(loc.extensions.transform.lang, Some(en_us)); /// let key: Key = "h0".parse().expect("Parsing key failed."); /// let value: Value = "hybrid".parse().expect("Parsing value failed."); -/// assert_eq!( -/// loc.extensions.transform.fields.get(&key), -/// Some(&value) -/// ); +/// assert_eq!(loc.extensions.transform.fields.get(&key), Some(&value)); /// ``` /// [`Unicode BCP47 T Extensions`]: https://unicode.org/reports/tr35/#t_Extension /// [`RFC 6497`]: https://www.ietf.org/rfc/rfc6497.txt @@ -110,8 +101,7 @@ impl Transform { /// ``` /// use icu::locid::Locale; /// - /// let mut loc: Locale = "en-US-t-es-AR".parse() - /// .expect("Parsing failed."); + /// let mut loc: Locale = "en-US-t-es-AR".parse().expect("Parsing failed."); /// /// assert_eq!(loc.extensions.transform.is_empty(), false); /// ``` diff --git a/components/locid/src/extensions/transform/value.rs b/components/locid/src/extensions/transform/value.rs index f7f8018ca74..ab954915493 100644 --- a/components/locid/src/extensions/transform/value.rs +++ b/components/locid/src/extensions/transform/value.rs @@ -29,10 +29,8 @@ const TRUE_TVALUE: TinyAsciiStr<8> = tinystr::tinystr!(8, "true"); /// ``` /// use icu::locid::extensions::transform::Value; /// -/// let value1: Value = "hybrid".parse() -/// .expect("Failed to parse a Value."); -/// let value2: Value = "hybrid-foobar".parse() -/// .expect("Failed to parse a Value."); +/// let value1: Value = "hybrid".parse().expect("Failed to parse a Value."); +/// let value2: Value = "hybrid-foobar".parse().expect("Failed to parse a Value."); /// /// assert_eq!(&value1.to_string(), "hybrid"); /// assert_eq!(&value2.to_string(), "hybrid-foobar"); @@ -46,8 +44,7 @@ impl Value { /// ``` /// use icu::locid::extensions::transform::Value; /// - /// let value = Value::from_bytes(b"hybrid") - /// .expect("Parsing failed."); + /// let value = Value::from_bytes(b"hybrid").expect("Parsing failed."); /// /// assert_eq!(&value.to_string(), "hybrid"); /// ``` diff --git a/components/locid/src/extensions/unicode/attribute.rs b/components/locid/src/extensions/unicode/attribute.rs index 0135a3aad19..a84c52c80de 100644 --- a/components/locid/src/extensions/unicode/attribute.rs +++ b/components/locid/src/extensions/unicode/attribute.rs @@ -19,8 +19,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::unicode::Attribute; /// -/// let attr: Attribute = "buddhist".parse() -/// .expect("Failed to parse an Attribute."); +/// let attr: Attribute = "buddhist".parse().expect("Failed to parse an Attribute."); /// /// assert_eq!(attr, "buddhist"); /// ``` @@ -38,8 +37,7 @@ impl Attribute { /// ``` /// use icu::locid::extensions::unicode::Attribute; /// - /// let attribute = Attribute::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let attribute = Attribute::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(attribute, "foobar"); /// ``` @@ -67,8 +65,7 @@ impl Attribute { /// ``` /// use icu::locid::extensions::unicode::Attribute; /// - /// let attribute = Attribute::from_bytes(b"foobar") - /// .expect("Parsing failed."); + /// let attribute = Attribute::from_bytes(b"foobar").expect("Parsing failed."); /// /// assert_eq!(attribute.as_str(), "foobar"); /// ``` diff --git a/components/locid/src/extensions/unicode/attributes.rs b/components/locid/src/extensions/unicode/attributes.rs index def0e17dc2e..c7e0ef3dd6f 100644 --- a/components/locid/src/extensions/unicode/attributes.rs +++ b/components/locid/src/extensions/unicode/attributes.rs @@ -16,10 +16,10 @@ use core::ops::Deref; /// ``` /// use icu::locid::extensions::unicode::{Attribute, Attributes}; /// -/// let attribute1: Attribute = "foobar".parse() -/// .expect("Failed to parse a variant subtag."); +/// let attribute1: Attribute = "foobar".parse().expect("Failed to parse a variant subtag."); /// -/// let attribute2: Attribute = "testing".parse() +/// let attribute2: Attribute = "testing" +/// .parse() /// .expect("Failed to parse a variant subtag."); /// let mut v = vec![attribute1, attribute2]; /// v.sort(); @@ -28,7 +28,6 @@ use core::ops::Deref; /// let attributes: Attributes = Attributes::from_vec_unchecked(v); /// assert_eq!(attributes.to_string(), "foobar-testing"); /// ``` -/// #[derive(Default, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)] pub struct Attributes(Vec); @@ -55,10 +54,8 @@ impl Attributes { /// ``` /// use icu::locid::extensions::unicode::{Attribute, Attributes}; /// - /// let attribute1: Attribute = "foobar".parse() - /// .expect("Parsing failed."); - /// let attribute2: Attribute = "testing".parse() - /// .expect("Parsing failed."); + /// let attribute1: Attribute = "foobar".parse().expect("Parsing failed."); + /// let attribute2: Attribute = "testing".parse().expect("Parsing failed."); /// let mut v = vec![attribute1, attribute2]; /// v.sort(); /// v.dedup(); @@ -80,10 +77,8 @@ impl Attributes { /// ``` /// use icu::locid::extensions::unicode::{Attribute, Attributes}; /// - /// let attribute1: Attribute = "foobar".parse() - /// .expect("Parsing failed."); - /// let attribute2: Attribute = "testing".parse() - /// .expect("Parsing failed."); + /// let attribute1: Attribute = "foobar".parse().expect("Parsing failed."); + /// let attribute2: Attribute = "testing".parse().expect("Parsing failed."); /// let mut v = vec![attribute1, attribute2]; /// /// let mut attributes: Attributes = Attributes::from_vec_unchecked(v); diff --git a/components/locid/src/extensions/unicode/key.rs b/components/locid/src/extensions/unicode/key.rs index 9203bff83ba..5ddaf3e9fbd 100644 --- a/components/locid/src/extensions/unicode/key.rs +++ b/components/locid/src/extensions/unicode/key.rs @@ -18,8 +18,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::unicode::Key; /// -/// let key1: Key = "ca".parse() -/// .expect("Failed to parse a Key."); +/// let key1: Key = "ca".parse().expect("Failed to parse a Key."); /// /// assert_eq!(key1, "ca"); /// ``` @@ -37,8 +36,7 @@ impl Key { /// ``` /// use icu::locid::extensions::unicode::Key; /// - /// let key = Key::from_bytes(b"ca") - /// .expect("Parsing failed."); + /// let key = Key::from_bytes(b"ca").expect("Parsing failed."); /// /// assert_eq!(key, "ca"); /// ``` diff --git a/components/locid/src/extensions/unicode/keywords.rs b/components/locid/src/extensions/unicode/keywords.rs index 66a6ade3481..0edd91d4727 100644 --- a/components/locid/src/extensions/unicode/keywords.rs +++ b/components/locid/src/extensions/unicode/keywords.rs @@ -26,12 +26,10 @@ use super::Value; /// Manually build up a [`Keywords`] object: /// /// ``` -/// use icu::locid::extensions::unicode::{Keywords, Key, Value}; +/// use icu::locid::extensions::unicode::{Key, Keywords, Value}; /// -/// let key: Key = "hc".parse() -/// .expect("Failed to parse a Key."); -/// let value: Value = "h23".parse() -/// .expect("Failed to parse a Value."); +/// let key: Key = "hc".parse().expect("Failed to parse a Key."); +/// let value: Value = "h23".parse().expect("Failed to parse a Value."); /// let keywords: Keywords = vec![(key, value)].into_iter().collect(); /// /// assert_eq!(&keywords.to_string(), "hc-h23"); @@ -40,10 +38,9 @@ use super::Value; /// Access a [`Keywords`] object from a [`Locale`]: /// /// ``` -/// use icu::locid::{Locale, unicode_ext_key, unicode_ext_value}; +/// use icu::locid::{unicode_ext_key, unicode_ext_value, Locale}; /// -/// let loc: Locale = "und-u-hc-h23-kc-true".parse() -/// .expect("Valid BCP-47"); +/// let loc: Locale = "und-u-hc-h23-kc-true".parse().expect("Valid BCP-47"); /// /// assert_eq!( /// loc.extensions.unicode.keywords.get(&unicode_ext_key!("ca")), @@ -58,10 +55,7 @@ use super::Value; /// Some(&unicode_ext_value!("true")) /// ); /// -/// assert_eq!( -/// loc.extensions.unicode.keywords.to_string(), -/// "hc-h23-kc" -/// ); +/// assert_eq!(loc.extensions.unicode.keywords.to_string(), "hc-h23-kc"); /// ``` /// /// [`Locale`]: crate::Locale @@ -88,8 +82,8 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::Locale; /// use icu::locid::extensions::unicode::Keywords; + /// use icu::locid::Locale; /// /// let loc1 = Locale::from_bytes(b"und-t-h0-hybrid").unwrap(); /// let loc2 = Locale::from_bytes(b"und-u-ca-buddhist").unwrap(); @@ -107,17 +101,14 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::{Keywords, Key, Value}; + /// use icu::locid::extensions::unicode::{Key, Keywords, Value}; /// use litemap::LiteMap; /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "gregory".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); + /// let value: Value = "gregory".parse().expect("Failed to parse a Value."); /// let keywords: Keywords = vec![(key, value)].into_iter().collect(); /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); /// assert!(&keywords.contains_key(&key)); /// ``` pub fn contains_key(&self, key: &Q) -> bool @@ -134,16 +125,13 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::{Keywords, Key, Value}; + /// use icu::locid::extensions::unicode::{Key, Keywords, Value}; /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "buddhist".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); + /// let value: Value = "buddhist".parse().expect("Failed to parse a Value."); /// let keywords: Keywords = vec![(key, value)].into_iter().collect(); /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); /// assert_eq!( /// keywords.get(&key).map(|v| v.to_string()), /// Some("buddhist".to_string()) @@ -164,19 +152,15 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::{Keywords, Key, Value}; + /// use icu::locid::extensions::unicode::{Key, Keywords, Value}; /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); - /// let value: Value = "buddhist".parse() - /// .expect("Failed to parse a Value."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); + /// let value: Value = "buddhist".parse().expect("Failed to parse a Value."); /// let mut keywords: Keywords = vec![(key, value)].into_iter().collect(); /// - /// let key: Key = "ca".parse() - /// .expect("Failed to parse a Key."); + /// let key: Key = "ca".parse().expect("Failed to parse a Key."); /// if let Some(value) = keywords.get_mut(&key) { - /// *value = "gregory".parse() - /// .expect("Failed to parse a Value."); + /// *value = "gregory".parse().expect("Failed to parse a Value."); /// } /// assert_eq!( /// keywords.get(&key).map(|v| v.to_string()), @@ -196,23 +180,21 @@ impl Keywords { /// # Examples /// /// ``` - /// use std::str::FromStr; - /// use std::string::ToString; - /// use icu::locid::unicode_ext_key; - /// use icu::locid::Locale; /// use icu::locid::extensions::unicode::Key; /// use icu::locid::extensions::unicode::Value; + /// use icu::locid::unicode_ext_key; + /// use icu::locid::Locale; + /// use std::str::FromStr; + /// use std::string::ToString; /// /// const CA_KEY: Key = unicode_ext_key!("ca"); /// let japanese = Value::from_str("japanese").expect("valid extension subtag"); /// let buddhist = Value::from_str("buddhist").expect("valid extension subtag"); /// - /// let mut loc: Locale = "und-u-hello-ca-buddhist-hc-h12".parse() + /// let mut loc: Locale = "und-u-hello-ca-buddhist-hc-h12" + /// .parse() /// .expect("valid BCP-47 identifier"); - /// let old_value = loc.extensions.unicode.keywords.set( - /// CA_KEY, - /// japanese - /// ); + /// let old_value = loc.extensions.unicode.keywords.set(CA_KEY, japanese); /// /// assert_eq!(old_value, Some(buddhist)); /// assert_eq!(loc, "und-u-hello-ca-japanese-hc-h12"); @@ -226,8 +208,8 @@ impl Keywords { /// # Example /// /// ``` - /// use std::str::FromStr; /// use icu::locid::Locale; + /// use std::str::FromStr; /// /// let mut loc: Locale = "und-u-hello-ca-buddhist-hc-h12".parse().unwrap(); /// loc.extensions.unicode.keywords.clear(); diff --git a/components/locid/src/extensions/unicode/mod.rs b/components/locid/src/extensions/unicode/mod.rs index fdf4b305b84..1b9a144dae9 100644 --- a/components/locid/src/extensions/unicode/mod.rs +++ b/components/locid/src/extensions/unicode/mod.rs @@ -11,18 +11,14 @@ //! # Examples //! //! ``` +//! use icu::locid::extensions::unicode::{Attribute, Key, Unicode, Value}; //! use icu::locid::{LanguageIdentifier, Locale}; -//! use icu::locid::extensions::unicode::{Unicode, Key, Value, Attribute}; //! -//! let mut loc: Locale = "en-US-u-foobar-hc-h12".parse() -//! .expect("Parsing failed."); +//! let mut loc: Locale = "en-US-u-foobar-hc-h12".parse().expect("Parsing failed."); //! -//! let key: Key = "hc".parse() -//! .expect("Parsing key failed."); -//! let value: Value = "h12".parse() -//! .expect("Parsing value failed."); -//! let attribute: Attribute = "foobar".parse() -//! .expect("Parsing attribute failed."); +//! let key: Key = "hc".parse().expect("Parsing key failed."); +//! let value: Value = "h12".parse().expect("Parsing value failed."); +//! let attribute: Attribute = "foobar".parse().expect("Parsing attribute failed."); //! //! assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value)); //! assert!(loc.extensions.unicode.attributes.contains(&attribute)); @@ -62,16 +58,14 @@ use litemap::LiteMap; /// # Examples /// /// ``` -/// use icu::locid::Locale; /// use icu::locid::extensions::unicode::{Key, Value}; +/// use icu::locid::Locale; /// -/// let mut loc: Locale = "de-u-hc-h12-ca-buddhist".parse() -/// .expect("Parsing failed."); +/// let mut loc: Locale = "de-u-hc-h12-ca-buddhist".parse().expect("Parsing failed."); /// /// let key: Key = "ca".parse().expect("Parsing key failed."); /// let value: Value = "buddhist".parse().expect("Parsing value failed."); -/// assert_eq!(loc.extensions.unicode.keywords.get(&key), -/// Some(&value)); +/// assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value)); /// ``` #[derive(Clone, PartialEq, Eq, Debug, Default, Hash, PartialOrd, Ord)] #[allow(missing_docs)] // TODO(#1028) - Add missing docs. @@ -106,8 +100,7 @@ impl Unicode { /// ``` /// use icu::locid::Locale; /// - /// let loc: Locale = "en-US-u-foo".parse() - /// .expect("Parsing failed."); + /// let loc: Locale = "en-US-u-foo".parse().expect("Parsing failed."); /// /// assert_eq!(loc.extensions.unicode.is_empty(), false); /// ``` @@ -121,8 +114,8 @@ impl Unicode { /// # Example /// /// ``` - /// use std::str::FromStr; /// use icu::locid::Locale; + /// use std::str::FromStr; /// /// let mut loc: Locale = "und-t-mul-u-hello-ca-buddhist-hc-h12".parse().unwrap(); /// loc.extensions.unicode.clear(); diff --git a/components/locid/src/extensions/unicode/value.rs b/components/locid/src/extensions/unicode/value.rs index 9c425ed823e..438a346bf72 100644 --- a/components/locid/src/extensions/unicode/value.rs +++ b/components/locid/src/extensions/unicode/value.rs @@ -22,12 +22,9 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::extensions::unicode::Value; /// -/// let value1: Value = "gregory".parse() -/// .expect("Failed to parse a Value."); -/// let value2: Value = "islamic-civil".parse() -/// .expect("Failed to parse a Value."); -/// let value3: Value = "true".parse() -/// .expect("Failed to parse a Value."); +/// let value1: Value = "gregory".parse().expect("Failed to parse a Value."); +/// let value2: Value = "islamic-civil".parse().expect("Failed to parse a Value."); +/// let value3: Value = "true".parse().expect("Failed to parse a Value."); /// /// assert_eq!(&value1.to_string(), "gregory"); /// assert_eq!(&value2.to_string(), "islamic-civil"); @@ -50,8 +47,7 @@ impl Value { /// ``` /// use icu::locid::extensions::unicode::Value; /// - /// let value = Value::from_bytes(b"buddhist") - /// .expect("Parsing failed."); + /// let value = Value::from_bytes(b"buddhist").expect("Parsing failed."); /// /// assert_eq!(&value.to_string(), "buddhist"); /// ``` diff --git a/components/locid/src/langid.rs b/components/locid/src/langid.rs index e89c1c91dfc..ebcaa9b3f31 100644 --- a/components/locid/src/langid.rs +++ b/components/locid/src/langid.rs @@ -20,8 +20,7 @@ use alloc::string::ToString; /// ``` /// use icu::locid::LanguageIdentifier; /// -/// let li: LanguageIdentifier = "en-US".parse() -/// .expect("Failed to parse."); +/// let li: LanguageIdentifier = "en-US".parse().expect("Failed to parse."); /// /// assert_eq!(li.language, "en"); /// assert_eq!(li.script, None); @@ -49,8 +48,7 @@ use alloc::string::ToString; /// ``` /// use icu::locid::LanguageIdentifier; /// -/// let li: LanguageIdentifier = "eN_latn_Us-Valencia".parse() -/// .expect("Failed to parse."); +/// let li: LanguageIdentifier = "eN_latn_Us-Valencia".parse().expect("Failed to parse."); /// /// assert_eq!(li.language, "en"); /// assert_eq!(li.script.unwrap(), "Latn"); @@ -81,8 +79,7 @@ impl LanguageIdentifier { /// ``` /// use icu::locid::LanguageIdentifier; /// - /// let li = LanguageIdentifier::from_bytes(b"en-US") - /// .expect("Parsing failed."); + /// let li = LanguageIdentifier::from_bytes(b"en-US").expect("Parsing failed."); /// /// assert_eq!(li.to_string(), "en-US"); /// ``` @@ -114,8 +111,7 @@ impl LanguageIdentifier { /// ``` /// use icu::locid::LanguageIdentifier; /// - /// let li = LanguageIdentifier::from_locale_bytes(b"en-US-x-posix") - /// .expect("Parsing failed."); + /// let li = LanguageIdentifier::from_locale_bytes(b"en-US-x-posix").expect("Parsing failed."); /// /// assert_eq!(li.to_string(), "en-US"); /// ``` @@ -153,7 +149,10 @@ impl LanguageIdentifier { /// ``` /// use icu::locid::LanguageIdentifier; /// - /// assert_eq!(LanguageIdentifier::canonicalize("pL_latn_pl"), Ok("pl-Latn-PL".to_string())); + /// assert_eq!( + /// LanguageIdentifier::canonicalize("pL_latn_pl"), + /// Ok("pl-Latn-PL".to_string()) + /// ); /// ``` pub fn canonicalize>(input: S) -> Result { let lang_id = Self::from_bytes(input.as_ref())?; @@ -325,8 +324,8 @@ impl PartialEq for LanguageIdentifier { /// # Examples /// /// ``` -/// use icu::locid::LanguageIdentifier; /// use icu::locid::language; +/// use icu::locid::LanguageIdentifier; /// /// let language = language!("en"); /// let li = LanguageIdentifier::from(language); @@ -346,8 +345,8 @@ impl From for LanguageIdentifier { /// # Examples /// /// ``` -/// use icu::locid::LanguageIdentifier; /// use icu::locid::script; +/// use icu::locid::LanguageIdentifier; /// /// let script = script!("latn"); /// let li = LanguageIdentifier::from(Some(script)); @@ -367,8 +366,8 @@ impl From> for LanguageIdentifier { /// # Examples /// /// ``` -/// use icu::locid::LanguageIdentifier; /// use icu::locid::region; +/// use icu::locid::LanguageIdentifier; /// /// let region = region!("US"); /// let li = LanguageIdentifier::from(Some(region)); @@ -389,7 +388,7 @@ impl From> for LanguageIdentifier { /// /// ``` /// use icu::locid::LanguageIdentifier; -/// use icu::locid::{language, script, region}; +/// use icu::locid::{language, region, script}; /// /// let lang = language!("en"); /// let script = script!("Latn"); diff --git a/components/locid/src/lib.rs b/components/locid/src/lib.rs index 8d7bd84d03f..d6a655c5337 100644 --- a/components/locid/src/lib.rs +++ b/components/locid/src/lib.rs @@ -22,16 +22,13 @@ //! # Examples //! //! ``` -//! use icu::locid::Locale; //! use icu::locid::subtags::{Language, Region}; +//! use icu::locid::Locale; //! -//! let mut loc: Locale = "en-US".parse() -//! .expect("Parsing failed."); +//! let mut loc: Locale = "en-US".parse().expect("Parsing failed."); //! -//! let lang: Language = "en".parse() -//! .expect("Parsing failed."); -//! let region: Region = "US".parse() -//! .expect("Parsing failed."); +//! let lang: Language = "en".parse().expect("Parsing failed."); +//! let region: Region = "US".parse().expect("Parsing failed."); //! //! assert_eq!(loc.id.language, lang); //! assert_eq!(loc.id.script, None); @@ -47,7 +44,7 @@ //! ## Macros //! //! ```rust -//! use icu::locid::{language, region, langid}; +//! use icu::locid::{langid, language, region}; //! //! let lid = langid!("EN_US"); //! diff --git a/components/locid/src/locale.rs b/components/locid/src/locale.rs index 19de8840cbb..d808cf7a52d 100644 --- a/components/locid/src/locale.rs +++ b/components/locid/src/locale.rs @@ -22,11 +22,10 @@ use core::str::FromStr; /// # Examples /// /// ``` -/// use icu::locid::Locale; /// use icu::locid::extensions::unicode::{Key, Value}; +/// use icu::locid::Locale; /// -/// let loc: Locale = "en-US-u-ca-buddhist".parse() -/// .expect("Failed to parse."); +/// let loc: Locale = "en-US-u-ca-buddhist".parse().expect("Failed to parse."); /// /// assert_eq!(loc.id.language, "en"); /// assert_eq!(loc.id.script, None); @@ -36,8 +35,7 @@ use core::str::FromStr; /// /// let key: Key = "ca".parse().expect("Parsing key failed."); /// let value: Value = "buddhist".parse().expect("Parsing value failed."); -/// assert_eq!(loc.extensions.unicode.keywords.get(&key), -/// Some(&value)); +/// assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value)); /// ``` /// /// # Parsing @@ -59,7 +57,8 @@ use core::str::FromStr; /// ``` /// use icu::locid::Locale; /// -/// let loc: Locale = "eN_latn_Us-Valencia_u-hC-H12".parse() +/// let loc: Locale = "eN_latn_Us-Valencia_u-hC-H12" +/// .parse() /// .expect("Failed to parse."); /// /// assert_eq!(loc.id.language, "en"); @@ -87,8 +86,7 @@ impl Locale { /// ``` /// use icu::locid::Locale; /// - /// let loc = Locale::from_bytes("en-US-u-hc-h12".as_bytes()) - /// .expect("Parsing failed."); + /// let loc = Locale::from_bytes("en-US-u-hc-h12".as_bytes()).expect("Parsing failed."); /// /// assert_eq!(loc.to_string(), "en-US-u-hc-h12"); /// ``` @@ -121,7 +119,10 @@ impl Locale { /// ``` /// use icu::locid::Locale; /// - /// assert_eq!(Locale::canonicalize("pL_latn_pl-U-HC-H12"), Ok("pl-Latn-PL-u-hc-h12".to_string())); + /// assert_eq!( + /// Locale::canonicalize("pL_latn_pl-U-HC-H12"), + /// Ok("pl-Latn-PL-u-hc-h12".to_string()) + /// ); /// ``` pub fn canonicalize>(input: S) -> Result { let locale = Self::from_bytes(input.as_ref())?; @@ -319,8 +320,8 @@ impl PartialEq for Locale { /// # Examples /// /// ``` -/// use icu::locid::Locale; /// use icu::locid::language; +/// use icu::locid::Locale; /// /// let language = language!("en"); /// let loc = Locale::from(language); @@ -340,8 +341,8 @@ impl From for Locale { /// # Examples /// /// ``` -/// use icu::locid::Locale; /// use icu::locid::script; +/// use icu::locid::Locale; /// /// let script = script!("latn"); /// let loc = Locale::from(Some(script)); @@ -361,8 +362,8 @@ impl From> for Locale { /// # Examples /// /// ``` -/// use icu::locid::Locale; /// use icu::locid::region; +/// use icu::locid::Locale; /// /// let region = region!("US"); /// let loc = Locale::from(Some(region)); @@ -383,7 +384,7 @@ impl From> for Locale { /// /// ``` /// use icu::locid::Locale; -/// use icu::locid::{language, script, region}; +/// use icu::locid::{language, region, script}; /// /// let lang = language!("en"); /// let script = script!("Latn"); diff --git a/components/locid/src/macros.rs b/components/locid/src/macros.rs index 830f24686ef..4061f010565 100644 --- a/components/locid/src/macros.rs +++ b/components/locid/src/macros.rs @@ -102,7 +102,7 @@ macro_rules! region { /// # Examples /// /// ``` -/// use icu::locid::{variant, subtags::Variant}; +/// use icu::locid::{subtags::Variant, variant}; /// /// const POSIX: Variant = variant!("Posix"); /// @@ -133,7 +133,7 @@ macro_rules! variant { /// # Examples /// /// ``` -/// use icu::locid::{LanguageIdentifier, langid}; +/// use icu::locid::{langid, LanguageIdentifier}; /// /// const DE_AT: LanguageIdentifier = langid!("de_at"); /// @@ -152,7 +152,9 @@ macro_rules! variant { /// /// Use runtime parsing instead: /// ``` -/// "de_at-foobar".parse::().unwrap(); +/// "de_at-foobar" +/// .parse::() +/// .unwrap(); /// ``` /// /// [`LanguageIdentifier`]: crate::LanguageIdentifier @@ -183,7 +185,7 @@ macro_rules! langid { /// # Examples /// /// ``` -/// use icu::locid::{Locale, locale}; +/// use icu::locid::{locale, Locale}; /// /// const DE_AT: Locale = locale!("de_at"); /// @@ -236,8 +238,8 @@ macro_rules! locale { /// # Examples /// /// ``` -/// use icu::locid::unicode_ext_key; /// use icu::locid::extensions::unicode::{Key, Value}; +/// use icu::locid::unicode_ext_key; /// use icu::locid::Locale; /// use writeable::Writeable; /// @@ -272,9 +274,9 @@ macro_rules! unicode_ext_key { /// # Examples /// /// ``` -/// use icu::locid::{unicode_ext_key, unicode_ext_value}; /// use icu::locid::extensions::unicode::{Key, Value}; /// use icu::locid::Locale; +/// use icu::locid::{unicode_ext_key, unicode_ext_value}; /// use writeable::Writeable; /// /// const CALENDAR_KEY: Key = unicode_ext_key!("ca"); @@ -318,8 +320,8 @@ macro_rules! unicode_ext_value { /// # Examples /// /// ``` -/// use icu::locid::transform_ext_key; /// use icu::locid::extensions::transform::{Key, Value}; +/// use icu::locid::transform_ext_key; /// use icu::locid::Locale; /// use writeable::Writeable; /// diff --git a/components/locid/src/subtags/language.rs b/components/locid/src/subtags/language.rs index b45dbd47f91..a8e6001a8d8 100644 --- a/components/locid/src/subtags/language.rs +++ b/components/locid/src/subtags/language.rs @@ -18,8 +18,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::subtags::Language; /// -/// let language: Language = "en".parse() -/// .expect("Failed to parse a language subtag."); +/// let language: Language = "en".parse().expect("Failed to parse a language subtag."); /// ``` /// /// If the [`Language`] has no value assigned, it serializes to a string `"und"`, which @@ -54,8 +53,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let lang = Language::from_bytes(b"en") - /// .expect("Parsing failed."); + /// let lang = Language::from_bytes(b"en").expect("Parsing failed."); /// /// assert_eq!(lang, "en"); /// ``` @@ -120,8 +118,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let lang = Language::from_bytes(b"en") - /// .expect("Parsing failed."); + /// let lang = Language::from_bytes(b"en").expect("Parsing failed."); /// /// let raw = lang.into_raw(); /// let lang = unsafe { Language::from_raw_unchecked(raw) }; @@ -139,8 +136,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let lang = Language::from_bytes(b"en") - /// .expect("Parsing failed."); + /// let lang = Language::from_bytes(b"en").expect("Parsing failed."); /// /// let raw = lang.into_raw(); /// let lang = unsafe { Language::from_raw_unchecked(raw) }; @@ -175,8 +171,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let lang = Language::from_bytes(b"en") - /// .expect("Parsing failed."); + /// let lang = Language::from_bytes(b"en").expect("Parsing failed."); /// /// assert_eq!(lang.as_str(), "en"); /// ``` @@ -195,8 +190,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let mut lang: Language = "csb".parse() - /// .expect("Parsing failed."); + /// let mut lang: Language = "csb".parse().expect("Parsing failed."); /// /// assert_eq!(lang.as_str(), "csb"); /// @@ -216,8 +210,7 @@ impl Language { /// ``` /// use icu::locid::subtags::Language; /// - /// let mut lang: Language = "und".parse() - /// .expect("Parsing failed."); + /// let mut lang: Language = "und".parse().expect("Parsing failed."); /// /// assert_eq!(lang.is_empty(), true); /// diff --git a/components/locid/src/subtags/mod.rs b/components/locid/src/subtags/mod.rs index 0f272dc3adb..a663c14259b 100644 --- a/components/locid/src/subtags/mod.rs +++ b/components/locid/src/subtags/mod.rs @@ -23,16 +23,12 @@ //! # Examples //! //! ``` -//! use icu::locid::subtags::{Language, Script, Region, Variant}; -//! -//! let language: Language = "en".parse() -//! .expect("Failed to parse a lanuage subtag."); -//! let script: Script = "arab".parse() -//! .expect("Failed to parse a script subtag."); -//! let region: Region = "cn".parse() -//! .expect("Failed to parse a region subtag."); -//! let variant: Variant = "MacOS".parse() -//! .expect("Failed to parse a variant subtag."); +//! use icu::locid::subtags::{Language, Region, Script, Variant}; +//! +//! let language: Language = "en".parse().expect("Failed to parse a lanuage subtag."); +//! let script: Script = "arab".parse().expect("Failed to parse a script subtag."); +//! let region: Region = "cn".parse().expect("Failed to parse a region subtag."); +//! let variant: Variant = "MacOS".parse().expect("Failed to parse a variant subtag."); //! //! assert_eq!(language, "en"); //! assert_eq!(script, "Arab"); diff --git a/components/locid/src/subtags/region.rs b/components/locid/src/subtags/region.rs index b9b59ed8bc0..2a531ae548a 100644 --- a/components/locid/src/subtags/region.rs +++ b/components/locid/src/subtags/region.rs @@ -16,8 +16,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::subtags::Region; /// -/// let region: Region = "DE".parse() -/// .expect("Failed to parse a region subtag."); +/// let region: Region = "DE".parse().expect("Failed to parse a region subtag."); /// ``` /// /// [`unicode_region_id`]: https://unicode.org/reports/tr35/#unicode_region_id @@ -38,8 +37,7 @@ impl Region { /// ``` /// use icu::locid::subtags::Region; /// - /// let region = Region::from_bytes(b"fr") - /// .expect("Parsing failed."); + /// let region = Region::from_bytes(b"fr").expect("Parsing failed."); /// /// assert_eq!(region, "FR"); /// ``` @@ -106,8 +104,7 @@ impl Region { /// ``` /// use icu::locid::subtags::Region; /// - /// let region = Region::from_bytes(b"us") - /// .expect("Parsing failed."); + /// let region = Region::from_bytes(b"us").expect("Parsing failed."); /// /// let raw = region.into_raw(); /// let region = unsafe { Region::from_raw_unchecked(raw) }; @@ -125,8 +122,7 @@ impl Region { /// ``` /// use icu::locid::subtags::Region; /// - /// let region = Region::from_bytes(b"us") - /// .expect("Parsing failed."); + /// let region = Region::from_bytes(b"us").expect("Parsing failed."); /// /// let raw = region.into_raw(); /// let region = unsafe { Region::from_raw_unchecked(raw) }; @@ -149,8 +145,7 @@ impl Region { /// ``` /// use icu::locid::subtags::Region; /// - /// let region = Region::from_bytes(b"it") - /// .expect("Parsing failed."); + /// let region = Region::from_bytes(b"it").expect("Parsing failed."); /// /// assert_eq!(region.as_str(), "IT"); /// ``` @@ -168,8 +163,7 @@ impl Region { /// ``` /// use icu::locid::subtags::Region; /// - /// let region = Region::from_bytes(b"us") - /// .expect("Parsing failed."); + /// let region = Region::from_bytes(b"us").expect("Parsing failed."); /// /// assert_eq!(region.is_alphabetic(), true); /// ``` diff --git a/components/locid/src/subtags/script.rs b/components/locid/src/subtags/script.rs index f36c21d1444..29d35a8d184 100644 --- a/components/locid/src/subtags/script.rs +++ b/components/locid/src/subtags/script.rs @@ -16,8 +16,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::subtags::Script; /// -/// let script: Script = "Latn".parse() -/// .expect("Failed to parse a script subtag."); +/// let script: Script = "Latn".parse().expect("Failed to parse a script subtag."); /// ``` /// /// [`unicode_script_id`]: https://unicode.org/reports/tr35/#unicode_script_id @@ -37,8 +36,7 @@ impl Script { /// ``` /// use icu::locid::subtags::Script; /// - /// let script = Script::from_bytes(b"Latn") - /// .expect("Parsing failed."); + /// let script = Script::from_bytes(b"Latn").expect("Parsing failed."); /// /// assert_eq!(script, "Latn"); /// ``` @@ -100,8 +98,7 @@ impl Script { /// ``` /// use icu::locid::subtags::Script; /// - /// let script = Script::from_bytes(b"Latn") - /// .expect("Parsing failed."); + /// let script = Script::from_bytes(b"Latn").expect("Parsing failed."); /// /// let raw = script.into_raw(); /// let script = unsafe { Script::from_raw_unchecked(raw) }; @@ -119,8 +116,7 @@ impl Script { /// ``` /// use icu::locid::subtags::Script; /// - /// let script = Script::from_bytes(b"Latn") - /// .expect("Parsing failed."); + /// let script = Script::from_bytes(b"Latn").expect("Parsing failed."); /// /// let raw = script.into_raw(); /// let script = unsafe { Script::from_raw_unchecked(raw) }; @@ -143,8 +139,7 @@ impl Script { /// ``` /// use icu::locid::subtags::Script; /// - /// let script = Script::from_bytes(b"Latn") - /// .expect("Parsing failed."); + /// let script = Script::from_bytes(b"Latn").expect("Parsing failed."); /// /// assert_eq!(script.as_str(), "Latn"); /// ``` diff --git a/components/locid/src/subtags/variant.rs b/components/locid/src/subtags/variant.rs index 9ffa5fcdae8..9d8f5025868 100644 --- a/components/locid/src/subtags/variant.rs +++ b/components/locid/src/subtags/variant.rs @@ -18,8 +18,7 @@ use tinystr::TinyAsciiStr; /// ``` /// use icu::locid::subtags::Variant; /// -/// let variant: Variant = "macos".parse() -/// .expect("Failed to parse a variant subtag."); +/// let variant: Variant = "macos".parse().expect("Failed to parse a variant subtag."); /// ``` /// /// [`unicode_variant_id`]: https://unicode.org/reports/tr35/#unicode_variant_id @@ -40,8 +39,7 @@ impl Variant { /// ``` /// use icu::locid::subtags::Variant; /// - /// let variant = Variant::from_bytes(b"posix") - /// .expect("Parsing failed."); + /// let variant = Variant::from_bytes(b"posix").expect("Parsing failed."); /// /// assert_eq!(variant, "posix"); /// ``` @@ -114,8 +112,7 @@ impl Variant { /// ``` /// use icu::locid::subtags::Variant; /// - /// let variant = Variant::from_bytes(b"posix") - /// .expect("Parsing failed."); + /// let variant = Variant::from_bytes(b"posix").expect("Parsing failed."); /// /// let raw = variant.into_raw(); /// let variant = unsafe { Variant::from_raw_unchecked(raw) }; @@ -133,8 +130,7 @@ impl Variant { /// ``` /// use icu::locid::subtags::Variant; /// - /// let variant = Variant::from_bytes(b"posix") - /// .expect("Parsing failed."); + /// let variant = Variant::from_bytes(b"posix").expect("Parsing failed."); /// /// let raw = variant.into_raw(); /// let variant = unsafe { Variant::from_raw_unchecked(raw) }; @@ -157,8 +153,7 @@ impl Variant { /// ``` /// use icu::locid::subtags::Variant; /// - /// let variant = Variant::from_bytes(b"macos") - /// .expect("Parsing failed."); + /// let variant = Variant::from_bytes(b"macos").expect("Parsing failed."); /// /// assert_eq!(variant.as_str(), "macos"); /// ``` diff --git a/components/locid/src/subtags/variants.rs b/components/locid/src/subtags/variants.rs index 2fcbd813e52..6cb6662d62d 100644 --- a/components/locid/src/subtags/variants.rs +++ b/components/locid/src/subtags/variants.rs @@ -18,11 +18,9 @@ use core::ops::Deref; /// ``` /// use icu::locid::subtags::{Variant, Variants}; /// -/// let variant1: Variant = "posix".parse() -/// .expect("Failed to parse a variant subtag."); +/// let variant1: Variant = "posix".parse().expect("Failed to parse a variant subtag."); /// -/// let variant2: Variant = "macos".parse() -/// .expect("Failed to parse a variant subtag."); +/// let variant2: Variant = "macos".parse().expect("Failed to parse a variant subtag."); /// let mut v = vec![variant1, variant2]; /// v.sort(); /// v.dedup(); @@ -30,7 +28,6 @@ use core::ops::Deref; /// let variants: Variants = Variants::from_vec_unchecked(v); /// assert_eq!(variants.to_string(), "macos-posix"); /// ``` -/// #[derive(Default, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)] pub struct Variants(Option>); @@ -58,10 +55,8 @@ impl Variants { /// ``` /// use icu::locid::subtags::{Variant, Variants}; /// - /// let variant1: Variant = "posix".parse() - /// .expect("Parsing failed."); - /// let variant2: Variant = "macos".parse() - /// .expect("Parsing failed."); + /// let variant1: Variant = "posix".parse().expect("Parsing failed."); + /// let variant2: Variant = "macos".parse().expect("Parsing failed."); /// let mut v = vec![variant1, variant2]; /// v.sort(); /// v.dedup(); @@ -88,10 +83,8 @@ impl Variants { /// ``` /// use icu::locid::subtags::{Variant, Variants}; /// - /// let variant1: Variant = "posix".parse() - /// .expect("Parsing failed."); - /// let variant2: Variant = "macos".parse() - /// .expect("Parsing failed."); + /// let variant1: Variant = "posix".parse().expect("Parsing failed."); + /// let variant2: Variant = "macos".parse().expect("Parsing failed."); /// let mut v = vec![variant1, variant2]; /// v.sort(); /// v.dedup(); @@ -113,10 +106,8 @@ impl Variants { /// ``` /// use icu::locid::subtags::{Variant, Variants}; /// - /// let variant1: Variant = "posix".parse() - /// .expect("Parsing failed."); - /// let variant2: Variant = "macos".parse() - /// .expect("Parsing failed."); + /// let variant1: Variant = "posix".parse().expect("Parsing failed."); + /// let variant2: Variant = "macos".parse().expect("Parsing failed."); /// let mut v = vec![variant1, variant2]; /// v.sort(); /// v.dedup(); @@ -147,10 +138,8 @@ impl Variants { /// ``` /// use icu::locid::subtags::{Variant, Variants}; /// - /// let variant1: Variant = "posix".parse() - /// .expect("Parsing failed."); - /// let variant2: Variant = "macos".parse() - /// .expect("Parsing failed."); + /// let variant1: Variant = "posix".parse().expect("Parsing failed."); + /// let variant2: Variant = "macos".parse().expect("Parsing failed."); /// let mut v = vec![variant1, variant2]; /// v.sort(); /// v.dedup(); diff --git a/components/locid/src/zerovec.rs b/components/locid/src/zerovec.rs index 32c5936e4de..59dd7c3f585 100644 --- a/components/locid/src/zerovec.rs +++ b/components/locid/src/zerovec.rs @@ -20,8 +20,8 @@ //! and then use [`Locale::cmp_bytes()`] to perform an efficient, zero-allocation lookup. //! //! ``` -//! use std::str::FromStr; //! use icu_locid::Locale; +//! use std::str::FromStr; //! use zerovec::ZeroMap; //! //! // ZeroMap from locales to integers @@ -55,9 +55,9 @@ //! tuple, and then construct the [`LanguageIdentifier`] externally. //! //! ``` +//! use icu_locid::subtags::{Language, Region, Script}; //! use icu_locid::LanguageIdentifier; -//! use icu_locid::subtags::{Language, Script, Region}; -//! use icu_locid::{language, script, region, langid}; +//! use icu_locid::{langid, language, region, script}; //! use zerovec::ZeroMap; //! //! // ZeroMap from integer to LSR (language-script-region) @@ -65,16 +65,17 @@ //! (5, (language!("de"), None, Some(region!("DE")))), //! (10, (language!("en"), None, Some(region!("US")))), //! (15, (language!("my"), None, Some(region!("MM")))), -//! (20, (language!("sr"), Some(script!("Cyrl")), Some(region!("ME")))), +//! ( +//! 20, +//! (language!("sr"), Some(script!("Cyrl")), Some(region!("ME"))), +//! ), //! (25, (language!("zh"), None, Some(region!("TW")))), //! ]; //! let zm: ZeroMap, Option)> = //! data.iter().copied().collect(); //! //! // Construct a LanguageIdentifier from a tuple entry -//! let lid: LanguageIdentifier = zm.get_copied(&25) -//! .expect("element is present") -//! .into(); +//! let lid: LanguageIdentifier = zm.get_copied(&25).expect("element is present").into(); //! //! assert_eq!(lid, langid!("zh-TW")); //! ``` @@ -90,8 +91,8 @@ //! deserialization. //! //! ``` -//! use icu_locid::Locale; //! use icu_locid::langid; +//! use icu_locid::Locale; //! use zerovec::ZeroMap; //! //! // ZeroMap from integer to locale string @@ -156,16 +157,15 @@ unsafe impl ULE for Language { /// # Example /// /// ``` -/// use icu::locid::subtags::Language; /// use icu::locid::language; +/// use icu::locid::subtags::Language; /// use zerovec::ZeroVec; /// -/// let zv = ZeroVec::::parse_byte_slice(b"de\0fr\0arsar\0") -/// .expect("Valid language subtags"); +/// let zv = +/// ZeroVec::::parse_byte_slice(b"de\0fr\0arsar\0").expect("Valid language subtags"); /// assert_eq!(zv.get(1), Some(language!("fr"))); /// -/// ZeroVec::::parse_byte_slice(b"invalid") -/// .expect_err("Invalid byte slice"); +/// ZeroVec::::parse_byte_slice(b"invalid").expect_err("Invalid byte slice"); /// ``` /// /// [`ZeroVec`]: zerovec::ZeroVec @@ -216,16 +216,15 @@ unsafe impl ULE for Script { /// # Example /// /// ``` -/// use icu::locid::subtags::Script; /// use icu::locid::script; +/// use icu::locid::subtags::Script; /// use zerovec::ZeroVec; /// -/// let zv = ZeroVec::