about summary refs log tree commit diff
path: root/src/libstd_unicode/unicode.py
diff options
context:
space:
mode:
authorBehnam Esfahbod <behnam@zwnj.org>2017-06-30 17:23:55 -0600
committerBehnam Esfahbod <behnam@zwnj.org>2017-07-21 12:09:02 -0600
commit42f886110afd8c944c9a94d82d65e17bf704f03f (patch)
tree5311572ea61086b52f8f5b53f0015cff137df381 /src/libstd_unicode/unicode.py
parent7ebb6eedca28995ab12ac9e87a2785474ca226c6 (diff)
downloadrust-42f886110afd8c944c9a94d82d65e17bf704f03f.tar.gz
rust-42f886110afd8c944c9a94d82d65e17bf704f03f.zip
[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.
Diffstat (limited to 'src/libstd_unicode/unicode.py')
-rwxr-xr-xsrc/libstd_unicode/unicode.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/libstd_unicode/unicode.py b/src/libstd_unicode/unicode.py
index 5b921a946d1..1fac859242e 100755
--- a/src/libstd_unicode/unicode.py
+++ b/src/libstd_unicode/unicode.py
@@ -560,9 +560,32 @@ if __name__ == "__main__":
             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: <http://www.unicode.org/versions/>
+#[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")