API reference
Docstrings
Interfaces.Interfaces
— ModuleInterfaces
A Julia package for specifying and testing interfaces (conditions verified by a set of methods applied to a type).
Interfaces.Arguments
— TypeArguments{names,T}
Arguments(; kw...)
Arguments(nt::NamedTuple)
A wrapper for a NamedTuple
.
Interfaces.Interface
— TypeInterface{Components}
Abstract supertype for all Interfaces.jl interfaces.
Components is an Tuple
of Symbol
.
Interfaces.components
— Functioncomponents(::Type{<:Interface})
Returns the components of the interface, as a NamedTuple
of NamedTuple
.
Interfaces.description
— Functiondescription(::Type{<:Interface})
Returns a String
description of an interface.
Interfaces.implemented_trait
— Methodimplemented_trait(T::Type{<:Interface}, obj)
implemented_trait(T::Type{<:Interface{Option}}, obj)
Provides a single type for using interface implementation as a trait.
Returns Implemented{T}()
or NotImplemented{T}()
.
Interfaces.implements
— Functionimplements(::Type{<:Interface}, obj)
implements(::Type{<:Interface{Options}}, obj)
Returns whether an object implements an interface, as a Bool
.
obj
can be an be an object or a Type
.
Options can be a Symbol
or a Tuple
of Symbol
passed to the type parameter of the Interface
, to check if optional interfaces are implemented by the obj
.
Without specifying Options
, the return value specifies that at least all the mandatory components of the interace are implemented.
Interfaces.optional_keys
— Functionoptional_keys(T::Type{<:Interface}, O::Type)
Get the keys for the optional components of an Interface
, as a tuple os Symbol
.
Interfaces.requiredtype
— Functionrequiredtype(::Type{<:Interface})
Returns the supertype required for all interface implementations.
Interfaces.test
— Functiontest(; kw...)
test(mod::Module; kw...)
test(::Type; kw...)
test(::Type{<:Interface}; kw...)
test(::Type{<:Interface}, mod::Module; kw...)
test(::Type{<:Interface}, type::Type, [test_objects]; kw...)
Test if an interface is implemented correctly, returning true
or false
.
There are a number of ways to select implementations to test:
- With no arguments, test all defined
Interface
s currenty imported. - If a
Module
is passed, allInterface
implementations defined in it will be tested. This is probably the best option to put in package tests. - If only an
Interface
is passed, all implementations of it are tested. - If only a
Type
is passed, all interfaces it implements are tested. - If both a
Module
and anInterface
are passed, test the intersection. of implementations of theInterface
for theModule
. - If an
Interface
andType
are passed, the implementation for that type will be tested.
If no interface type is passed, Interfaces.jl will find all the interfaces available and test them.
Interfaces.test_objects
— Functiontest_objects(T::Type{<:Interface}, O::Type)
Get the test object(s) for type O
and interface T
.
Interfaces.@implements
— Macro@implements(interface, objtype, test_objects)
Declare that an interface implements an interface, or multipleinterfaces.
The macro can only be used once per module for any one type. To define multiple interfaces a type implements, combine them in square brackets.
Example
Here we implement the IterationInterface for Base julia, indicating with (:indexing, :reverse)
that our object can be indexed and works with Iterators.reverse
:
using BaseInterfaces, Interfaces
@implements BaseInterfaces.IterationInterface{(:indexing,:reverse)} MyObject [MyObject(1:10), MyObject(10:-1:1)]
Interfaces.@interface
— Macro@interface(interfacename, components, [description])
Define an interface that can apply to types <: Any
.
components = (
mandatory = (
length = x -> length(x) = prod(size(x)),
ndims = x -> ndims(x) = length(size(x)),
),
optional = (;)
)
description = "A description of the interface"
@interface MyInterface Any components description
Index
Interfaces.Interfaces
BaseInterfaces.ArrayInterface
BaseInterfaces.DictInterface
BaseInterfaces.IterationInterface
BaseInterfaces.SetInterface
Interfaces.Arguments
Interfaces.Interface
Interfaces.components
Interfaces.description
Interfaces.implemented_trait
Interfaces.implements
Interfaces.optional_keys
Interfaces.requiredtype
Interfaces.test
Interfaces.test_objects
Interfaces.@implements
Interfaces.@interface