1 // Copyright 2017 The UNIC Project Developers.
2 //
3 // See the COPYRIGHT file at the top-level directory of this distribution.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 
11 //! Taxonomy and contracts for Character Property types.
12 
13 use core::fmt::Debug;
14 use core::hash::Hash;
15 
16 /// A Character Property, defined for some or all Unicode characters.
17 pub trait CharProperty: PartialCharProperty + Debug + Eq + Hash {
18     /// The *abbreviated name* of the property.
prop_abbr_name() -> &'static str19     fn prop_abbr_name() -> &'static str;
20 
21     /// The *long name* of the property.
prop_long_name() -> &'static str22     fn prop_long_name() -> &'static str;
23 
24     /// The *human-readable* name of the property.
prop_human_name() -> &'static str25     fn prop_human_name() -> &'static str;
26 }
27 
28 /// A Character Property defined for some characters.
29 ///
30 /// Examples: `Decomposition_Type`, `Numeric_Type`
31 pub trait PartialCharProperty: Copy {
32     /// The property value for the character, or None.
of(ch: char) -> Option<Self>33     fn of(ch: char) -> Option<Self>;
34 }
35 
36 /// A Character Property defined on all characters.
37 ///
38 /// Examples: `Age`, `Name`, `General_Category`, `Bidi_Class`
39 pub trait TotalCharProperty: PartialCharProperty + Default {
40     /// The property value for the character.
of(ch: char) -> Self41     fn of(ch: char) -> Self;
42 }
43 
44 impl<T: TotalCharProperty> PartialCharProperty for T {
of(ch: char) -> Option<Self>45     fn of(ch: char) -> Option<Self> {
46         Some(<Self as TotalCharProperty>::of(ch))
47     }
48 }
49