@ts-rust/std - v0.0.5
    Preparing search index...

    Interface Clone<T>

    Defines a type T that is cloneable, providing a method to create a new, independent instance of itself.

    The Clone interface ensures that any type implementing it can produce a duplicate of its current instance via the clone method. The type T represents the specific type of the implementing instance.

    Similar to Rust's Clone trait, this interface is intended for types that need explicit duplication logic (e.g., objects or complex structures), as opposed to Primitive types, which are implicitly copied by value. Unlike reference types that might share state, a clone implementation should produce a distinct instance, though the depth of the copy (shallow or deep) is left to the implementor.

    T is the type of the instance that implements this interface. Typically, this is the class or type itself (e.g., a class MyType would implement Clone<MyType>).

    class MyType implements Clone<MyType> {
    constructor(public value: number) {}

    clone(this: MyType): MyType {
    return new MyType(this.value);
    }
    }

    const original = new MyType(42);
    const duplicate = original.clone();
    expect(duplicate.value).toBe(original.value); // same value
    expect(duplicate).not.toBe(original); // different reference
    interface Clone<T> {
        clone(this: T): T;
        clone(this: Clone<T>): T;
    }

    Type Parameters

    • T

    Implemented by

    Index

    Methods

    Methods