JuliaCollections / LeftChildRightSiblingTrees.jl

Memory-efficient representation of a tree with arbitrary number of children/node
MIT License
16 stars 5 forks source link

Cannot `convert` an object of type Node{T} to an object of type T #9

Closed zygmuntszpak closed 4 years ago

zygmuntszpak commented 4 years ago

I am having trouble figuring out what the convert method is supposed to be for a custom struct.

using Parameters
using LeftChildRightSiblingTrees

@with_kw struct DigitalContour
    id::Int = 0
    is_outer::Bool = false
    pixels::Vector{CartesianIndex{2}} = Vector{CartesianIndex{2}}(undef, 0)
end

root = Node(DigitalContour(is_outer = false))
addchild(root, Node(DigitalContour(id = 1)))

ERROR: MethodError: Cannot convert an object of type Node{DigitalContour} to an object of type DigitalContour Closest candidates are: convert(::Type{T}, ::T) where T at essentials.jl:168 DigitalContour(::Any, ::Any, ::Any) at /home/zygmunt/.julia/packages/Parameters/l76EM/src/Parameters.jl:478 Stacktrace: [1] Node{DigitalContour}(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:45 [2] Node(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:52 [3] addchild(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:90 [4] top-level scope at none:0

Part of my problem is that I don't really understand how the call to convert is being called. Thanks for any advice you might have.

oxinabox commented 4 years ago

addchild does not take a Node It takes the content of the node.

addchild(root, DigitalContour(id = 1)) should work

zygmuntszpak commented 4 years ago

Thank you!