style: Document gecko_string_cache.

This commit is contained in:
Emilio Cobos Álvarez 2017-01-02 04:58:35 +01:00
parent e9d3ac03a9
commit 2cebd3bc96
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 30 additions and 2 deletions

View file

@ -2,6 +2,8 @@
* 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/. */
//! A type to represent a namespace.
use gecko_bindings::structs::nsIAtom;
use std::borrow::{Borrow, Cow};
use std::fmt;
@ -13,9 +15,11 @@ macro_rules! ns {
() => { $crate::string_cache::Namespace(atom!("")) }
}
/// A Gecko namespace is just a wrapped atom.
#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
pub struct Namespace(pub Atom);
/// A Gecko WeakNamespace is a wrapped WeakAtom.
#[derive(Hash)]
pub struct WeakNamespace(WeakAtom);
@ -51,11 +55,14 @@ impl Borrow<WeakNamespace> for Namespace {
}
impl WeakNamespace {
/// Trivially construct a WeakNamespace.
#[inline]
pub unsafe fn new<'a>(atom: *mut nsIAtom) -> &'a Self {
&*(atom as *const WeakNamespace)
}
/// Clone this WeakNamespace to obtain a strong reference to the same
/// underlying namespace.
#[inline]
pub fn clone(&self) -> Namespace {
Namespace(self.0.clone())