solnic / drops

🛠️ Tools for working with data effectively - data contracts using types, schemas, domain validation rules, type-safe casting, and more.
Other
258 stars 7 forks source link

define type as a cast #46

Open uhoreg opened 8 months ago

uhoreg commented 8 months ago

I'd like to device a custom type that uses a cast, but

use Drops.Type, (cast(string(), caster: Caster) |> string())

doesn't seem to work, giving the error:

    The following arguments were given to Drops.Type.infer_constraints/1:

        # 1
        {:cast, {{:type, {:string, []}}, {:type, {:string, []}}, [caster: Caster]}}

    Attempted function clauses (showing 6 out of 6):

        def infer_constraints([])
        def infer_constraints(map) when is_map(map)
        def infer_constraints(type) when is_atom(type)
        def infer_constraints(predicates) when is_list(predicates)
        def infer_constraints({:type, {type, predicates}}) when length(predicates) > 0
        def infer_constraints({:type, {type, []}})

    (drops 0.2.0) lib/drops/type.ex:251: Drops.Type.infer_constraints/1
solnic commented 8 months ago

Same here :) Will be addressed in 0.2.1