IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

copyable

Defines Copyable and ImplicitlyCopyable, the traits for types whose value can be copied.

These are Mojo built-ins, so you don't need to import them.

comptime values

IsTriviallyCopyable

comptime IsTriviallyCopyable[T: AnyType] = conforms_to(T, TrivialRegisterPassable) if conforms_to(T, TrivialRegisterPassable) else T.__copy_ctor_is_trivial if conforms_to(T, Copyable) else conforms_to(T, Copyable)

Indicates whether T is Copyable with a trivial copy initializer.

A copy initializer is trivial when the compiler generates it and all of T's fields are themselves trivially copyable — the value can be copied by duplicating its bits to a new location with no additional side effects. Evaluates to False for non-Copyable types.

Parameters

  • T (AnyType): The type to check.

Traits

  • Copyable: The Copyable trait denotes a type whose value can be explicitly copied.
  • ImplicitlyCopyable: A marker trait to permit compiler to insert implicit calls to the copy constructor in order to make a copy of the object when needed.