API reference
Docstrings
Interfaces.Interfaces — ModuleInterfacesA 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
Interfaces currenty imported. - If a
Moduleis passed, allInterfaceimplementations defined in it will be tested. This is probably the best option to put in package tests. - If only an
Interfaceis passed, all implementations of it are tested. - If only a
Typeis passed, all interfaces it implements are tested. - If both a
Moduleand anInterfaceare passed, test the intersection. of implementations of theInterfacefor theModule. - If an
InterfaceandTypeare 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 descriptionIndex
BaseInterfaces.BaseInterfacesInterfaces.InterfacesBaseInterfaces.ArrayInterfaceBaseInterfaces.DictInterfaceBaseInterfaces.IterationInterfaceBaseInterfaces.SetInterfaceBaseInterfaces.StringInterfaceInterfaces.ArgumentsInterfaces.InterfaceInterfaces.componentsInterfaces.descriptionInterfaces.implemented_traitInterfaces.implementsInterfaces.optional_keysInterfaces.requiredtypeInterfaces.testInterfaces.test_objectsInterfaces.@implementsInterfaces.@interface