Skip to content

Commit 1057462

Browse files
committed
Some cleanups
1 parent cbfd7bd commit 1057462

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

scripts/unicode.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,10 @@ def emit_enums(f, script_list, extension_list, longforms, intersections):
188188
Emit the Script and ScriptExtension enums as well as any related utility functions
189189
"""
190190
f.write("""
191-
use core::convert::TryFrom;
192191
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
193192
#[non_exhaustive]
194193
#[allow(non_camel_case_types)]
195-
/// A value of the Script property
194+
/// A value of the `Script` property
196195
pub enum Script {
197196
/// Unknown script
198197
Unknown,
@@ -202,11 +201,11 @@ def emit_enums(f, script_list, extension_list, longforms, intersections):
202201
f.write("""}
203202
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
204203
#[non_exhaustive]
205-
/// A value for the Script_Extension property
204+
/// A value for the `Script_Extension` property
206205
///
207-
/// Script_Extension is one or more Script
206+
/// [`ScriptExtension`] is one or more [`Script`]
208207
///
209-
/// This is essentially an optimized version of Vec<Script>,
208+
/// This is essentially an optimized version of `Vec<Script>`,
210209
/// optimized by script sets and intersections actually present in Unicode.
211210
pub enum ScriptExtension {
212211
/// A single script
@@ -217,23 +216,8 @@ def emit_enums(f, script_list, extension_list, longforms, intersections):
217216
f.write(" /// %s\n %s,\n" % (longform, "".join(ext)))
218217
f.write("""}
219218
220-
impl From<Script> for ScriptExtension {
221-
fn from(script: Script) -> Self {
222-
ScriptExtension::Single(script)
223-
}
224-
}
225-
226-
impl TryFrom<ScriptExtension> for Script {
227-
type Error = ();
228-
fn try_from(ext: ScriptExtension) -> Result<Self, ()> {
229-
match ext {
230-
ScriptExtension::Single(s) => Ok(s),
231-
_ => Err(())
232-
}
233-
}
234-
}
235-
236219
impl Script {
220+
#[inline]
237221
pub(crate) fn inner_full_name(self) -> &'static str {
238222
match self {
239223
Script::Unknown => "Unknown",
@@ -243,6 +227,7 @@ def emit_enums(f, script_list, extension_list, longforms, intersections):
243227
f.write(""" }
244228
}
245229
230+
#[inline]
246231
pub(crate) fn inner_short_name(self) -> &'static str {
247232
match self {
248233
Script::Unknown => "",

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod tables;
88

99
pub use tables::{Script, ScriptExtension, UNICODE_VERSION};
1010

11+
use core::convert::TryFrom;
1112
use tables::{get_script, get_script_extension};
1213

1314
impl Script {
@@ -35,6 +36,22 @@ impl Script {
3536
}
3637
}
3738

39+
impl From<Script> for ScriptExtension {
40+
fn from(script: Script) -> Self {
41+
ScriptExtension::Single(script)
42+
}
43+
}
44+
45+
impl TryFrom<ScriptExtension> for Script {
46+
type Error = ();
47+
fn try_from(ext: ScriptExtension) -> Result<Self, ()> {
48+
match ext {
49+
ScriptExtension::Single(s) => Ok(s),
50+
_ => Err(()),
51+
}
52+
}
53+
}
54+
3855
impl Default for Script {
3956
fn default() -> Self {
4057
Script::Common

src/tables.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
/// that this version of unicode-script is based on.
1717
pub const UNICODE_VERSION: (u64, u64, u64) = (12, 0, 0);
1818

19-
use core::convert::TryFrom;
2019
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
2120
#[non_exhaustive]
2221
#[allow(non_camel_case_types)]
23-
/// A value of the Script property
22+
/// A value of the `Script` property
2423
pub enum Script {
2524
/// Unknown script
2625
Unknown,
@@ -331,11 +330,11 @@ pub enum Script {
331330
}
332331
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
333332
#[non_exhaustive]
334-
/// A value for the Script_Extension property
333+
/// A value for the `Script_Extension` property
335334
///
336-
/// Script_Extension is one or more Script
335+
/// [`ScriptExtension`] is one or more [`Script`]
337336
///
338-
/// This is essentially an optimized version of Vec<Script>,
337+
/// This is essentially an optimized version of `Vec<Script>`,
339338
/// optimized by script sets and intersections actually present in Unicode.
340339
pub enum ScriptExtension {
341340
/// A single script
@@ -472,23 +471,8 @@ pub enum ScriptExtension {
472471
DevaKndaOryaTelu,
473472
}
474473

475-
impl From<Script> for ScriptExtension {
476-
fn from(script: Script) -> Self {
477-
ScriptExtension::Single(script)
478-
}
479-
}
480-
481-
impl TryFrom<ScriptExtension> for Script {
482-
type Error = ();
483-
fn try_from(ext: ScriptExtension) -> Result<Self, ()> {
484-
match ext {
485-
ScriptExtension::Single(s) => Ok(s),
486-
_ => Err(())
487-
}
488-
}
489-
}
490-
491474
impl Script {
475+
#[inline]
492476
pub(crate) fn inner_full_name(self) -> &'static str {
493477
match self {
494478
Script::Unknown => "Unknown",
@@ -647,6 +631,7 @@ impl Script {
647631
}
648632
}
649633

634+
#[inline]
650635
pub(crate) fn inner_short_name(self) -> &'static str {
651636
match self {
652637
Script::Unknown => "",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy