Skip to content

Commit 42f8861

Browse files
committedJul 21, 2017
[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.
1 parent 7ebb6ee commit 42f8861

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed
 

‎src/libstd_unicode/tables.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,32 @@
1212

1313
#![allow(missing_docs, non_upper_case_globals, non_snake_case)]
1414

15-
/// The version of [Unicode](http://www.unicode.org/)
16-
/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
17-
pub const UNICODE_VERSION: (u32, u32, u32) = (10, 0, 0);
15+
/// Represents a Unicode Version.
16+
///
17+
/// See also: <http://www.unicode.org/versions/>
18+
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
19+
pub struct UnicodeVersion {
20+
/// Major version.
21+
pub major: u32,
22+
23+
/// Minor version.
24+
pub minor: u32,
25+
26+
/// Micro (or Update) version.
27+
pub micro: u32,
28+
29+
// Private field to keep struct expandable.
30+
_priv: (),
31+
}
32+
33+
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
34+
/// `CharExt` and `UnicodeStrPrelude` traits are based on.
35+
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
36+
major: 10,
37+
minor: 0,
38+
micro: 0,
39+
_priv: (),
40+
};
1841

1942

2043
// BoolTrie is a trie for representing a set of Unicode codepoints. It is

‎src/libstd_unicode/unicode.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,32 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
560560
pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode"
561561
unicode_version = re.search(pattern, readme.read()).groups()
562562
rf.write("""
563-
/// The version of [Unicode](http://www.unicode.org/)
564-
/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
565-
pub const UNICODE_VERSION: (u32, u32, u32) = (%s, %s, %s);
563+
/// Represents a Unicode Version.
564+
///
565+
/// See also: <http://www.unicode.org/versions/>
566+
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
567+
pub struct UnicodeVersion {
568+
/// Major version.
569+
pub major: u32,
570+
571+
/// Minor version.
572+
pub minor: u32,
573+
574+
/// Micro (or Update) version.
575+
pub micro: u32,
576+
577+
// Private field to keep struct expandable.
578+
_priv: (),
579+
}
580+
581+
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
582+
/// `CharExt` and `UnicodeStrPrelude` traits are based on.
583+
pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
584+
major: %s,
585+
minor: %s,
586+
micro: %s,
587+
_priv: (),
588+
};
566589
""" % unicode_version)
567590
(canon_decomp, compat_decomp, gencats, combines,
568591
to_upper, to_lower, to_title) = load_unicode_data("UnicodeData.txt")

0 commit comments

Comments
 (0)
Please sign in to comment.