deecpy

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2022 License: Unlicense Imports: 7 Imported by: 0

README

Go Reference GitHub Workflow Status (push) Codecov main GitHub license

Deecpy

Deecpy, The DeepCopy Library

Example

package main

import (
    "fmt"

    "github.com/unsafe-risk/deecpy"
)

// func deecpy.Copy[T any](dst, src *T) error
// func deecpy.Duplicate[T any](src T) (T, error)

type Person struct {
    Name string
    Age  int
    id   ID
}

type ID struct {
    UUID string
    email string
}

var john = Person{Name: "John", Age: 30, id: ID{UUID: "123", email: "john@example.com"}}
var jane = Person{Name: "Jane", Age: 25, id: ID{UUID: "456", email: "jane@example.com"}}

func main() {
    var john_copy Person
    err := deecpy.Copy(&john_copy, &john)
    if err != nil {
        panic(err)
    }

    fmt.Println("john:", john)
    fmt.Println("john_copy:", john_copy)

    jane_copy, err := deecpy.Duplicate(jane)
    if err != nil {
        panic(err)
    }

    fmt.Println("jane:", jane)
    fmt.Println("jane_copy:", jane_copy)
}

Go Playground

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigCopyString = false
View Source
var ErrUnsupportedType = errors.New("unsupported type")
View Source
var IgnoreUnsupportedTypes = true

Functions

func Copy

func Copy[T any](dst, src *T) error

Copy deeply copies the given object.

func Duplicate

func Duplicate[T any](src T) (T, error)

Duplicate returns a copy of the given object.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL