-
-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copy of slice doesn't replace the whole slice #182
Comments
Created this wrapper module to work around this issue: package copier
import (
"reflect"
"github.com/jinzhu/copier"
)
func Copy(dst, src interface{}) {
dv := reflect.ValueOf(dst)
tv := reflect.TypeOf(dst)
if dv.Kind() == reflect.Ptr {
dv = reflect.Indirect(dv)
tv = reflect.TypeOf(dv.Interface())
}
sv := reflect.ValueOf(src)
if sv.Kind() == reflect.Ptr {
sv = reflect.Indirect(sv)
}
if dv.Kind() == reflect.Slice {
dv.Set(reflect.MakeSlice(reflect.SliceOf(tv.Elem()), sv.Len(), sv.Len()))
}
copier.Copy(dst, src)
} |
Same problem. |
jheroy
added a commit
to jheroy/copier
that referenced
this issue
May 17, 2023
遇到同样的问题 |
jinzhu
added a commit
that referenced
this issue
Mar 17, 2024
fix #182 copy of slice doesn't replace the whole slice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproducible Example
Description
If this is expected behavior I would appreciate an option to override the entire destination slice. DeepCopy doesn't do it.
The issue appears to be introduced in 6ffbdf1
The text was updated successfully, but these errors were encountered: