{"id":29602054,"url":"https://github.com/dislogical/quack","last_synced_at":"2026-03-09T14:05:32.600Z","repository":{"id":19258957,"uuid":"22494834","full_name":"dislogical/quack","owner":"dislogical","description":"A compile-time duck typing library for D.","archived":false,"fork":false,"pushed_at":"2020-11-02T02:08:43.000Z","size":33,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-07T22:44:24.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dislogical.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-01T04:07:58.000Z","updated_at":"2024-01-26T19:55:52.000Z","dependencies_parsed_at":"2022-07-27T00:16:06.147Z","dependency_job_id":null,"html_url":"https://github.com/dislogical/quack","commit_stats":null,"previous_names":["dislogical/quack"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/dislogical/quack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dislogical%2Fquack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dislogical%2Fquack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dislogical%2Fquack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dislogical%2Fquack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dislogical","download_url":"https://codeload.github.com/dislogical/quack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dislogical%2Fquack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30297881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T13:46:43.843Z","status":"ssl_error","status_checked_at":"2026-03-09T13:46:42.821Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-20T13:37:49.750Z","updated_at":"2026-03-09T14:05:32.566Z","avatar_url":"https://github.com/dislogical.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"## quack\n[![Build Status](http://img.shields.io/travis/ColdenCullen/quack/master.svg?style=flat)](https://travis-ci.org/ColdenCullen/quack)\n[![Coverage](http://img.shields.io/coveralls/ColdenCullen/quack/master.svg?style=flat)](https://coveralls.io/r/ColdenCullen/quack)\n[![Release](http://img.shields.io/github/release/ColdenCullen/quack.svg?style=flat)](http://code.dlang.org/packages/quack)\n\nA library for enabling compile-time duck typing in D.\n\n#### Duck Typing\n\nDuck typing is a reference to the phrase \"if it walks like a duck, and quacks\nlike a duck, then it's probably a duck.\" The idea is that if a `struct` or\n`class` has all the same members as another, it should be usable as the other.\n\n#### Usage\n\nDuck exists so that you may treat non-related types as polymorphic, at compile\ntime. There are three primary ways to use quack:\n\n1) Taking objects as arguments: For this, you should use `extends!( A, B )`,\nwhich returns true if A \"extends\" B. It can do this by implementing all of the\nsame members B has, or by having a variable of type B that it has set to\n`alias this`.\n\n2) Storing pointers to objects: For this, you should use a `DuckPointer!A`,\nwhich can be created with `duck!A( B b )`, assuming B \"extends\" A (the actual\ncheck is done using `extends`, so see the docs on that). Note that this approach\nshould only be used when you need to actually store the object, as it is much\nslower than the pure template approach.\n\n3) Checking for the presence of a mixin: For this, you'll want\n`hasStringMixin!( A, mix )` or `hasTemplateMixin!( A, mix )`. These two\ntemplates will instantiate a struct with the given mixin, `mix`, and check if it is\ncompatible with the type given, `A`.\n\n#### Examples\n\n```d\nimport quack;\nimport std.stdio;\n\nstruct Base\n{\n  int x;\n}\n\nstruct Child1\n{\n  Base b;\n  alias b this;\n}\n\nstruct Child2\n{\n    int x;\n}\n\nvoid someFunction( T )( T t ) if( extends!( T, Base ) )\n{\n    writeln( t.x );\n}\n\nstruct HolderOfBase\n{\n    DuckPointer!Base myBase;\n}\n\nvoid main()\n{\n  someFunction( Child1() );\n  someFunction( Child2() );\n\n  auto aHolder1 = new HolderOfA( duck!Base( Child1() ) );\n  auto aHolder2 = new HolderOfA( duck!Base( Child2() ) );\n}\n```\n\n```d\nimport quack;\nimport std.stdio;\n\nenum myStringMixin = q{\n    void stringMember();\n};\n\nmixin template MyTemplateMixin( MemberType )\n{\n    MemberType templateMember;\n}\n\nvoid doAThing( T )( T t ) if( hasTemplateMixin!( T, MyTemplateMixin, float ) )\n{\n    // Doing a thing...\n}\n\nvoid doAnotherThing( T )( T t ) if( hasStringMixin!( T, myStringMixin ) )\n{\n    // Still doing things...\n}\n\nstruct TemplateMixinImpl\n{\n    mixin MyTemplateMixin!float;\n}\n\nstruct StringMixinImpl\n{\n    mixin( myStringMixin );\n}\n\nvoid main()\n{\n    doAThing( TemplateMixinImpl() );\n    doAnotherThing( StringMixinImpl() );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdislogical%2Fquack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdislogical%2Fquack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdislogical%2Fquack/lists"}