mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 18:15:01 +00:00
parent
d754722a04
commit
bfc2f5de85
@ -346,17 +346,16 @@ impl<T:?Sized> MarkerTrait for T { }
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
|
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
|
||||||
|
|
||||||
/// `PhantomData` is a way to tell the compiler about fake fields.
|
/// `PhantomData<T>` allows you to describe that a type acts as if it stores a value of type `T`,
|
||||||
/// Phantom data is required whenever type parameters are not used.
|
/// even though it does not. This allows you to inform the compiler about certain safety properties
|
||||||
/// The idea is that if the compiler encounters a `PhantomData<T>`
|
/// of your code.
|
||||||
/// instance, it will behave *as if* an instance of the type `T` were
|
///
|
||||||
/// present for the purpose of various automatic analyses.
|
/// Though they both have scary names, `PhantomData<T>` and "phantom types" are unrelated. 👻👻👻
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
|
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
|
||||||
/// prevent mismatches by enforcing types in the method implementations, although the struct
|
/// prevent mismatches by enforcing types in the method implementations:
|
||||||
/// doesn't actually contain values of the resource type.
|
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # trait ResType { fn foo(&self); };
|
/// # trait ResType { fn foo(&self); };
|
||||||
@ -397,11 +396,6 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
|
|||||||
/// commonly necessary if the structure is using an unsafe pointer
|
/// commonly necessary if the structure is using an unsafe pointer
|
||||||
/// like `*mut T` whose referent may be dropped when the type is
|
/// like `*mut T` whose referent may be dropped when the type is
|
||||||
/// dropped, as a `*mut T` is otherwise not treated as owned.
|
/// dropped, as a `*mut T` is otherwise not treated as owned.
|
||||||
///
|
|
||||||
/// FIXME. Better documentation and examples of common patterns needed
|
|
||||||
/// here! For now, please see [RFC 738][738] for more information.
|
|
||||||
///
|
|
||||||
/// [738]: https://github.com/rust-lang/rfcs/blob/master/text/0738-variance.md
|
|
||||||
#[lang="phantom_data"]
|
#[lang="phantom_data"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct PhantomData<T:?Sized>;
|
pub struct PhantomData<T:?Sized>;
|
||||||
|
Loading…
Reference in New Issue
Block a user