[src]

Module std::kinds::marker

Marker types are special types that are used with unsafe code to inform the compiler of special constraints. Marker types should only be needed when you are creating an abstraction that is implemented using unsafe code. In that case, you may want to embed some of the marker types below into your type.

ContravariantLifetime

As ContravariantType, but for lifetime parameters. Using ContravariantLifetime<'a> indicates that it is ok to substitute a shorter lifetime for 'a than the one you originally started with (e.g., you could convert 'static to any lifetime 'foo). This is appropriate for cases where you have an unsafe pointer that is actually a pointer into some memory with lifetime 'a, and thus you want to limit the lifetime of your data structure to 'a. An example of where this is used is the iterator for vectors.

ContravariantType

A marker type whose type parameter T is considered to be contravariant with respect to the type itself. This is (typically) used to indicate that an instance of the type T will be consumed (but not read from), even though that may not be apparent.

CovariantLifetime

As CovariantType, but for lifetime parameters. Using CovariantLifetime<'a> indicates that it is ok to substitute a longer lifetime for 'a than the one you originally started with (e.g., you could convert any lifetime 'foo to 'static). You almost certainly want ContravariantLifetime instead, or possibly InvariantLifetime. The only case where it would be appropriate is that you have a (type-casted, and hence hidden from the type system) function pointer with a signature like fn(&'a T) (and no other uses of 'a). In this case, it is ok to substitute a larger lifetime for 'a (e.g., fn(&'static T)), because the function is only becoming more selective in terms of what it accepts as argument.

CovariantType

A marker type whose type parameter T is considered to be covariant with respect to the type itself. This is (typically) used to indicate that an instance of the type T is being stored into memory and read from, even though that may not be apparent.

InvariantLifetime

As InvariantType, but for lifetime parameters. Using InvariantLifetime<'a> indicates that it is not ok to substitute any other lifetime for 'a besides its original value. This is appropriate for cases where you have an unsafe pointer that is actually a pointer into memory with lifetime 'a, and this pointer is itself stored in an inherently mutable location (such as a Cell).

InvariantType

A marker type whose type parameter T is considered to be invariant with respect to the type itself. This is (typically) used to indicate that instances of the type T may be read or written, even though that may not be apparent.

Managed

A type which is considered managed by the GC. This is typically embedded in other types.

NoCopy

A type which is considered "not POD", meaning that it is not implicitly copyable. This is typically embedded in other types to ensure that they are never copied, even if they lack a destructor.

NoSend

A type which is considered "not sendable", meaning that it cannot be safely sent between tasks, even if it is owned. This is typically embedded in other types, such as Gc, to ensure that their instances remain thread-local.

NoShare

A type which is considered "not sharable", meaning that its contents are not threadsafe, hence they cannot be shared between tasks.