unic_char_property/
property.rs

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
13use core::fmt::Debug;
14use core::hash::Hash;
15
16/// A Character Property, defined for some or all Unicode characters.
17pub trait CharProperty: PartialCharProperty + Debug + Eq + Hash {
18    /// The *abbreviated name* of the property.
19    fn prop_abbr_name() -> &'static str;
20
21    /// The *long name* of the property.
22    fn prop_long_name() -> &'static str;
23
24    /// The *human-readable* name of the property.
25    fn prop_human_name() -> &'static str;
26}
27
28/// A Character Property defined for some characters.
29///
30/// Examples: `Decomposition_Type`, `Numeric_Type`
31pub trait PartialCharProperty: Copy {
32    /// The property value for the character, or None.
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`
39pub trait TotalCharProperty: PartialCharProperty + Default {
40    /// The property value for the character.
41    fn of(ch: char) -> Self;
42}
43
44impl<T: TotalCharProperty> PartialCharProperty for T {
45    fn of(ch: char) -> Option<Self> {
46        Some(<Self as TotalCharProperty>::of(ch))
47    }
48}