pub unsafe trait Singleton { }
Expand description

This trait denotes a type which has at most one logical identity at all times. This is sufficient to make borrowing decisions based only on the type, without regards to value identity.

Implementers of the trait must uphold this contract, that any point during the execution of the program, there is at most one accessible logical value of this type. Much like how re-borrowings can make a type inaccessible, it is allowed for there to be more than one such binding, if the others are inaccessible due to unique borrowing.

Some examples would include:

  • A type with exactly one instance constructed during the main method
  • A type with only one static instance (including one wrapped behind e.g. a Mutex)
  • An uninhabited type
  • A type which is constructed with a unique lifetime brand

Any type which has a public constructor cannot meet this, Some non-examples include ZSTs like () and the Exists struct in this crate (when T is not a Singleton itself) Any type which implements Clone

Implementations on Foreign Types

Implementors