Skip to content

Commit 8bedc3e

Browse files
committed
Move trait impls that simply forward to something else to their own module
1 parent 57ff374 commit 8bedc3e

File tree

3 files changed

+91
-80
lines changed

3 files changed

+91
-80
lines changed

src/atom.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#![allow(non_upper_case_globals)]
11-
1210
use crate::dynamic_set::{Entry, DYNAMIC_SET};
1311
use crate::static_sets::StaticAtomSet;
1412
use debug_unreachable::debug_unreachable;
1513
use phf_shared;
16-
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1714
use std::borrow::Cow;
1815
use std::cmp::Ordering::{self, Equal};
1916
use std::fmt;
@@ -85,18 +82,6 @@ pub struct Atom<Static> {
8582
phantom: PhantomData<Static>,
8683
}
8784

88-
impl<Static: StaticAtomSet> ::precomputed_hash::PrecomputedHash for Atom<Static> {
89-
fn precomputed_hash(&self) -> u32 {
90-
self.get_hash()
91-
}
92-
}
93-
94-
impl<'a, Static: StaticAtomSet> From<&'a Atom<Static>> for Atom<Static> {
95-
fn from(atom: &'a Self) -> Self {
96-
atom.clone()
97-
}
98-
}
99-
10085
// FIXME: bound removed from the struct definition before of this error for pack_static:
10186
// "error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable"
10287
// https://github.com/rust-lang/rust/issues/57563
@@ -183,24 +168,6 @@ impl<Static: StaticAtomSet> Hash for Atom<Static> {
183168
}
184169
}
185170

186-
impl<Static: StaticAtomSet> PartialEq<str> for Atom<Static> {
187-
fn eq(&self, other: &str) -> bool {
188-
&self[..] == other
189-
}
190-
}
191-
192-
impl<Static: StaticAtomSet> PartialEq<Atom<Static>> for str {
193-
fn eq(&self, other: &Atom<Static>) -> bool {
194-
self == &other[..]
195-
}
196-
}
197-
198-
impl<Static: StaticAtomSet> PartialEq<String> for Atom<Static> {
199-
fn eq(&self, other: &String) -> bool {
200-
&self[..] == &other[..]
201-
}
202-
}
203-
204171
impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
205172
fn from(string_to_add: Cow<'a, str>) -> Self {
206173
let static_set = Static::get();
@@ -237,20 +204,6 @@ impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
237204
}
238205
}
239206

240-
impl<'a, Static: StaticAtomSet> From<&'a str> for Atom<Static> {
241-
#[inline]
242-
fn from(string_to_add: &str) -> Self {
243-
Atom::from(Cow::Borrowed(string_to_add))
244-
}
245-
}
246-
247-
impl<Static: StaticAtomSet> From<String> for Atom<Static> {
248-
#[inline]
249-
fn from(string_to_add: String) -> Self {
250-
Atom::from(Cow::Owned(string_to_add))
251-
}
252-
}
253-
254207
impl<Static: StaticAtomSet> Clone for Atom<Static> {
255208
#[inline(always)]
256209
fn clone(&self) -> Self {
@@ -305,13 +258,6 @@ impl<Static: StaticAtomSet> ops::Deref for Atom<Static> {
305258
}
306259
}
307260

308-
impl<Static: StaticAtomSet> fmt::Display for Atom<Static> {
309-
#[inline]
310-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
311-
<str as fmt::Display>::fmt(self, f)
312-
}
313-
}
314-
315261
impl<Static: StaticAtomSet> fmt::Debug for Atom<Static> {
316262
#[inline]
317263
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -348,32 +294,6 @@ impl<Static: StaticAtomSet> Ord for Atom<Static> {
348294
}
349295
}
350296

351-
impl<Static: StaticAtomSet> AsRef<str> for Atom<Static> {
352-
fn as_ref(&self) -> &str {
353-
&self
354-
}
355-
}
356-
357-
impl<Static: StaticAtomSet> Serialize for Atom<Static> {
358-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
359-
where
360-
S: Serializer,
361-
{
362-
let string: &str = self.as_ref();
363-
string.serialize(serializer)
364-
}
365-
}
366-
367-
impl<'a, Static: StaticAtomSet> Deserialize<'a> for Atom<Static> {
368-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
369-
where
370-
D: Deserializer<'a>,
371-
{
372-
let string: String = Deserialize::deserialize(deserializer)?;
373-
Ok(Atom::from(string))
374-
}
375-
}
376-
377297
// AsciiExt requires mutating methods, so we just implement the non-mutating ones.
378298
// We don't need to implement is_ascii because there's no performance improvement
379299
// over the one from &str.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
mod atom;
107107
mod dynamic_set;
108108
mod static_sets;
109+
mod trivial_impls;
109110

110111
pub use atom::Atom;
111112
pub use static_sets::{EmptyStaticAtomSet, PhfStrSet, StaticAtomSet};

src/trivial_impls.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2014 The Servo Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
use crate::{Atom, StaticAtomSet};
11+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
12+
use std::borrow::Cow;
13+
use std::fmt;
14+
15+
impl<Static: StaticAtomSet> ::precomputed_hash::PrecomputedHash for Atom<Static> {
16+
fn precomputed_hash(&self) -> u32 {
17+
self.get_hash()
18+
}
19+
}
20+
21+
impl<'a, Static: StaticAtomSet> From<&'a Atom<Static>> for Atom<Static> {
22+
fn from(atom: &'a Self) -> Self {
23+
atom.clone()
24+
}
25+
}
26+
27+
impl<Static: StaticAtomSet> PartialEq<str> for Atom<Static> {
28+
fn eq(&self, other: &str) -> bool {
29+
&self[..] == other
30+
}
31+
}
32+
33+
impl<Static: StaticAtomSet> PartialEq<Atom<Static>> for str {
34+
fn eq(&self, other: &Atom<Static>) -> bool {
35+
self == &other[..]
36+
}
37+
}
38+
39+
impl<Static: StaticAtomSet> PartialEq<String> for Atom<Static> {
40+
fn eq(&self, other: &String) -> bool {
41+
&self[..] == &other[..]
42+
}
43+
}
44+
45+
impl<'a, Static: StaticAtomSet> From<&'a str> for Atom<Static> {
46+
#[inline]
47+
fn from(string_to_add: &str) -> Self {
48+
Atom::from(Cow::Borrowed(string_to_add))
49+
}
50+
}
51+
52+
impl<Static: StaticAtomSet> From<String> for Atom<Static> {
53+
#[inline]
54+
fn from(string_to_add: String) -> Self {
55+
Atom::from(Cow::Owned(string_to_add))
56+
}
57+
}
58+
59+
impl<Static: StaticAtomSet> fmt::Display for Atom<Static> {
60+
#[inline]
61+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62+
<str as fmt::Display>::fmt(self, f)
63+
}
64+
}
65+
66+
impl<Static: StaticAtomSet> AsRef<str> for Atom<Static> {
67+
fn as_ref(&self) -> &str {
68+
&self
69+
}
70+
}
71+
72+
impl<Static: StaticAtomSet> Serialize for Atom<Static> {
73+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
74+
where
75+
S: Serializer,
76+
{
77+
let string: &str = self.as_ref();
78+
string.serialize(serializer)
79+
}
80+
}
81+
82+
impl<'a, Static: StaticAtomSet> Deserialize<'a> for Atom<Static> {
83+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
84+
where
85+
D: Deserializer<'a>,
86+
{
87+
let string: String = Deserialize::deserialize(deserializer)?;
88+
Ok(Atom::from(string))
89+
}
90+
}

0 commit comments

Comments
 (0)