diff options
author | Jack Moffitt <jack@metajack.im> | 2014-08-28 09:34:23 -0600 |
---|---|---|
committer | Jack Moffitt <jack@metajack.im> | 2014-09-08 20:21:42 -0600 |
commit | c6ab60dbfc6da7b4f800c9e40893c8b58413960c (patch) | |
tree | d1d74076cf7fa20e4f77ec7cb82cae98b67362cb /components/util/atom.rs | |
parent | db2f642c32fc5bed445bb6f2e45b0f6f0b4342cf (diff) | |
download | servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.tar.gz servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.zip |
Cargoify servo
Diffstat (limited to 'components/util/atom.rs')
-rw-r--r-- | components/util/atom.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/components/util/atom.rs b/components/util/atom.rs new file mode 100644 index 00000000000..49cb047768e --- /dev/null +++ b/components/util/atom.rs @@ -0,0 +1,43 @@ +/* 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/. */ + +//! Provides a wrapper around the Atom type in the string cache +//! crate. It's needed so that it can implement the Encodable +//! trait which is required by Servo. + +use serialize::{Encoder, Encodable}; +use std::fmt; +use std::hash::Hash; +use string_cache::atom; + +#[deriving(Clone, Eq, Hash, PartialEq)] +pub struct Atom { + atom: atom::Atom, +} + +impl Atom { + #[inline(always)] + pub fn from_slice(slice: &str) -> Atom { + Atom { + atom: atom::Atom::from_slice(slice) + } + } + + #[inline(always)] + pub fn as_slice<'t>(&'t self) -> &'t str { + self.atom.as_slice() + } +} + +impl fmt::Show for Atom { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:s}", self.atom.as_slice()) + } +} + +impl<E, S: Encoder<E>> Encodable<S, E> for Atom { + fn encode(&self, _s: &mut S) -> Result<(), E> { + Ok(()) + } +} |