Skip to content

Provides a flexible way to define function interfaces for abstract types in Julia, both for obligatory and optional methods with clear error handling and debug logging. Using a simple @interface macro, it allows default behaviors for optional interfaces, making it easy to enforce contracts in Julia code.

License

Notifications You must be signed in to change notification settings

kunzaatko/InterfaceFunctions.jl

Repository files navigation

InterfaceFunctions.jl Logo: A puzzle piece in Julia colours

InterfaceFunctions

Stable Dev Build Status Coverage Code Style: Blue ColPrac: Contributor's Guide on Collaborative Practices for Community Packages Aqua

InterfaceFunctions.jl provides a robust and flexible (although light and very simple) way to define and manage function interfaces of abstract types in Julia, supporting both obligatory (necessary to implement by the concrete type creator) and optional (ones that provide a default implementation) interfaces with clear error handling and debug logging.

Installation

To install InterfaceFunctions.jl, open the Julia REPL and run:

using Pkg
Pkg.add("InterfaceFunctions")

Quick Start

There is only a single macro that this package publicly provides: @interface.

Defining interfaces can be simply done by preceding a function (optional interface) or a call (obligatory interface) by the @interface macro:

using InterfaceFunctions

abstract type AbstractType end

@interface required_function(x::AbstractType)

struct ConcreteType <: AbstractType end

# This will throw an UnimplementedInterface error
try
    required_function(ConcreteType())
catch e
    println(e)
end

# Implement the interface
required_function(x::ConcreteType) = "Hello from ConcreteType!"
println(required_function(ConcreteType())) # Prints "Hello from ConcreteType!"

@interface optional_function(x::AbstractType) = "Hello from AbstractType!"
println(optional_function(ConcreteType())) # Prints "Hello from AbstractType!"

Documentation

For more detailed information, examples, and API reference, please refer to the stable documentation or the development documentation.

Contributing

All contributions are welcome. For instructions on how to contribute in the correct manner, read the Julia ColPrac collaboration practices guidelines or create a PR and let the maintainers help you out.

Citing

See CITATION.bib for the relevant reference(s).

About

Provides a flexible way to define function interfaces for abstract types in Julia, both for obligatory and optional methods with clear error handling and debug logging. Using a simple @interface macro, it allows default behaviors for optional interfaces, making it easy to enforce contracts in Julia code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages