aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2017-06-17 20:13:12 -0700
committerBobby Holley <bobbyholley@gmail.com>2017-06-20 11:59:10 -0700
commitdb8f59407f93e07111cf2bf0c5d691fcef4e40c9 (patch)
tree26eecb27588f7e3ccb89ad06f15ddd9b7fdd76e2 /components/selectors
parent2159d48382203ebb3deb75358d5cb06e0e55b103 (diff)
downloadservo-db8f59407f93e07111cf2bf0c5d691fcef4e40c9.tar.gz
servo-db8f59407f93e07111cf2bf0c5d691fcef4e40c9.zip
Hoist sink into selectors.
It probably makes more sense (eventually) to put it in SmallVec. MozReview-Commit-ID: AIBKCLiMNN2
Diffstat (limited to 'components/selectors')
-rw-r--r--components/selectors/lib.rs1
-rw-r--r--components/selectors/sink.rs31
2 files changed, 32 insertions, 0 deletions
diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs
index 16a7949cfa9..bde7acef189 100644
--- a/components/selectors/lib.rs
+++ b/components/selectors/lib.rs
@@ -20,6 +20,7 @@ pub mod matching;
pub mod parser;
#[cfg(test)] mod size_of_tests;
#[cfg(any(test, feature = "gecko_like_types"))] pub mod gecko_like_types;
+pub mod sink;
mod tree;
pub mod visitor;
diff --git a/components/selectors/sink.rs b/components/selectors/sink.rs
new file mode 100644
index 00000000000..3c57aa143c4
--- /dev/null
+++ b/components/selectors/sink.rs
@@ -0,0 +1,31 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//! Small helpers to abstract over different containers.
+#![deny(missing_docs)]
+
+use smallvec::{Array, SmallVec};
+
+/// A trait to abstract over a `push` method that may be implemented for
+/// different kind of types.
+///
+/// Used to abstract over `Array`, `SmallVec` and `Vec`, and also to implement a
+/// type which `push` method does only tweak a byte when we only need to check
+/// for the presence of something.
+pub trait Push<T> {
+ /// Push a value into self.
+ fn push(&mut self, value: T);
+}
+
+impl<T> Push<T> for Vec<T> {
+ fn push(&mut self, value: T) {
+ Vec::push(self, value);
+ }
+}
+
+impl<A: Array> Push<A::Item> for SmallVec<A> {
+ fn push(&mut self, value: A::Item) {
+ SmallVec::push(self, value);
+ }
+}