#totto2727/x/copy

Defines explicit logical-copy behavior for built-in MoonBit values and downstream types that need an independent mutable result. See the module README for consumer setup and package imports.

#Usage

Copy a mutable collection before changing it so the original value remains available for comparison or reuse.

///|
test {
let source = [1, 2]
let copied = Copy::copy(source)
copied[0] = 3
debug_inspect((source, copied), content="([1, 2], [3, 2])")
}

#Package behavior

  • Built-in implementations for scalars, collections, options, results, maps, and tuples
  • Recursive copying for composite values
  • An open trait for downstream value types to define their own semantics

#API

This README was generated from the share-artifact skill and README template.

Copy

pub(open) trait Copy {
fn copy(Self) -> Self
}

Describes values that can produce an independent logical copy.

Implementations for composite values recursively copy their contents. An implementation may share immutable internal storage when doing so cannot expose mutation through the returned value.

This trait is open so downstream value types can define their own copy semantics.

test {
let source = [1, 2]
let copied = Copy::copy(source)
copied[0] = 3
debug_inspect((source, copied), content="([1, 2], [3, 2])")
}
impl Copy for Unit
impl Copy for Bool
impl Copy for Byte
impl Copy for Char
impl Copy for Int
impl Copy for Int16
impl Copy for Int64
impl Copy for UInt
impl Copy for UInt16
impl Copy for UInt64
impl Copy for Float
impl Copy for Double
impl Copy for String
impl Copy for Option[T]
impl Copy for Result[Value, CopyError]
impl Copy for FixedArray[T]
impl Copy for ReadOnlyArray[T]
impl Copy for Bytes
impl Copy for Array[T]
impl Copy for Map[Key, Value]
impl Copy for Tuple2[First, Second]
impl Copy for Tuple3[First, Second, Third]

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io