From 7ebb6eedca28995ab12ac9e87a2785474ca226c6 Mon Sep 17 00:00:00 2001 From: Behnam Esfahbod Date: Fri, 30 Jun 2017 17:23:55 -0600 Subject: [PATCH 1/2] [libstd_unicode] Change UNICODE_VERSION to use u32 Use `u32` for version components, as `u64` is just an overkill, and `u32` is the default type for integers and the default type used for regular internal numbers. There's no expectation for Unicode Versions to even reach one thousand in the next hundered years. This is different from *package versions*, which may become something auto-generated and exceed human-friendly range of integer values. --- src/libstd_unicode/tables.rs | 2 +- src/libstd_unicode/unicode.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd_unicode/tables.rs b/src/libstd_unicode/tables.rs index 0938738b52cbd..63ed539887263 100644 --- a/src/libstd_unicode/tables.rs +++ b/src/libstd_unicode/tables.rs @@ -14,7 +14,7 @@ /// The version of [Unicode](http://www.unicode.org/) /// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on. -pub const UNICODE_VERSION: (u64, u64, u64) = (10, 0, 0); +pub const UNICODE_VERSION: (u32, u32, u32) = (10, 0, 0); // BoolTrie is a trie for representing a set of Unicode codepoints. It is diff --git a/src/libstd_unicode/unicode.py b/src/libstd_unicode/unicode.py index 5f9def02c7d11..5b921a946d1b3 100755 --- a/src/libstd_unicode/unicode.py +++ b/src/libstd_unicode/unicode.py @@ -562,7 +562,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props): rf.write(""" /// The version of [Unicode](http://www.unicode.org/) /// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on. -pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s); +pub const UNICODE_VERSION: (u32, u32, u32) = (%s, %s, %s); """ % unicode_version) (canon_decomp, compat_decomp, gencats, combines, to_upper, to_lower, to_title) = load_unicode_data("UnicodeData.txt") From 42f886110afd8c944c9a94d82d65e17bf704f03f Mon Sep 17 00:00:00 2001 From: Behnam Esfahbod Date: Fri, 30 Jun 2017 17:23:55 -0600 Subject: [PATCH 2/2] [libstd_unicode] Create UnicodeVersion type Create named struct `UnicodeVersion` to use instead of tuple type for `UNICODE_VERSION` value. This allows user to access the fields with meaningful field names: `major`, `minor`, and `micro`. Per request, an empty private field is added to the struct, so it can be extended in the future without API breakage. --- src/libstd_unicode/tables.rs | 29 ++++++++++++++++++++++++++--- src/libstd_unicode/unicode.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/libstd_unicode/tables.rs b/src/libstd_unicode/tables.rs index 63ed539887263..1e8a0be80966d 100644 --- a/src/libstd_unicode/tables.rs +++ b/src/libstd_unicode/tables.rs @@ -12,9 +12,32 @@ #![allow(missing_docs, non_upper_case_globals, non_snake_case)] -/// The version of [Unicode](http://www.unicode.org/) -/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on. -pub const UNICODE_VERSION: (u32, u32, u32) = (10, 0, 0); +/// Represents a Unicode Version. +/// +/// See also: +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct UnicodeVersion { + /// Major version. + pub major: u32, + + /// Minor version. + pub minor: u32, + + /// Micro (or Update) version. + pub micro: u32, + + // Private field to keep struct expandable. + _priv: (), +} + +/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of +/// `CharExt` and `UnicodeStrPrelude` traits are based on. +pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion { + major: 10, + minor: 0, + micro: 0, + _priv: (), +}; // BoolTrie is a trie for representing a set of Unicode codepoints. It is diff --git a/src/libstd_unicode/unicode.py b/src/libstd_unicode/unicode.py index 5b921a946d1b3..1fac859242eab 100755 --- a/src/libstd_unicode/unicode.py +++ b/src/libstd_unicode/unicode.py @@ -560,9 +560,32 @@ def emit_norm_module(f, canon, compat, combine, norm_props): pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode" unicode_version = re.search(pattern, readme.read()).groups() rf.write(""" -/// The version of [Unicode](http://www.unicode.org/) -/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on. -pub const UNICODE_VERSION: (u32, u32, u32) = (%s, %s, %s); +/// Represents a Unicode Version. +/// +/// See also: +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct UnicodeVersion { + /// Major version. + pub major: u32, + + /// Minor version. + pub minor: u32, + + /// Micro (or Update) version. + pub micro: u32, + + // Private field to keep struct expandable. + _priv: (), +} + +/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of +/// `CharExt` and `UnicodeStrPrelude` traits are based on. +pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion { + major: %s, + minor: %s, + micro: %s, + _priv: (), +}; """ % unicode_version) (canon_decomp, compat_decomp, gencats, combines, to_upper, to_lower, to_title) = load_unicode_data("UnicodeData.txt")