From b31470dddbc64f7a109b220e4e4be20bbb0fee69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 2 Jan 2017 00:20:03 +0100 Subject: [PATCH] style: Document the owning_handle module. --- components/style/owning_handle.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/components/style/owning_handle.rs b/components/style/owning_handle.rs index f4daf750cb0..1294bf7e59f 100644 --- a/components/style/owning_handle.rs +++ b/components/style/owning_handle.rs @@ -3,6 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #![allow(unsafe_code)] +#![deny(missing_docs)] + +//! A handle that encapsulate a reference to a given data along with its owner. use owning_ref::StableAddress; use std::ops::{Deref, DerefMut}; @@ -24,21 +27,23 @@ use std::ops::{Deref, DerefMut}; /// /// This does foist some unsafety onto the callback, which needs an `unsafe` /// block to dereference the pointer. It would be almost good enough for -/// OwningHandle to pass a transmuted &'statc reference to the callback +/// OwningHandle to pass a transmuted &'static reference to the callback /// since the lifetime is infinite as far as the minted handle is concerned. /// However, even an `Fn` callback can still allow the reference to escape /// via a `StaticMutex` or similar, which technically violates the safety /// contract. Some sort of language support in the lifetime system could /// make this API a bit nicer. pub struct OwningHandle - where O: StableAddress, H: Deref, + where O: StableAddress, + H: Deref, { handle: H, _owner: O, } impl Deref for OwningHandle - where O: StableAddress, H: Deref, + where O: StableAddress, + H: Deref, { type Target = H::Target; fn deref(&self) -> &H::Target { @@ -47,11 +52,13 @@ impl Deref for OwningHandle } unsafe impl StableAddress for OwningHandle - where O: StableAddress, H: StableAddress, + where O: StableAddress, + H: StableAddress, {} impl DerefMut for OwningHandle - where O: StableAddress, H: DerefMut, + where O: StableAddress, + H: DerefMut, { fn deref_mut(&mut self) -> &mut H::Target { self.handle.deref_mut() @@ -59,14 +66,15 @@ impl DerefMut for OwningHandle } impl OwningHandle - where O: StableAddress, H: Deref, + where O: StableAddress, + H: Deref, { /// Create a new OwningHandle. The provided callback will be invoked with /// a pointer to the object owned by `o`, and the returned value is stored /// as the object to which this `OwningHandle` will forward `Deref` and /// `DerefMut`. pub fn new(o: O, f: F) -> Self - where F: Fn(*const O::Target) -> H + where F: Fn(*const O::Target) -> H, { let h: H; {