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}
+API reference · Interfaces.jl 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).
sourceInterfaces.Arguments
— TypeArguments{names,T}
Arguments(; kw...)
-Arguments(nt::NamedTuple)
A wrapper for a NamedTuple
.
sourceInterfaces.Interface
— TypeInterface{Components}
Abstract supertype for all Interfaces.jl interfaces.
Components is an Tuple
of Symbol
.
sourceInterfaces.components
— Functioncomponents(::Type{<:Interface})
Returns the components of the interface, as a NamedTuple
of NamedTuple
.
sourceInterfaces.description
— Functiondescription(::Type{<:Interface})
Returns a String
description of an interface.
sourceInterfaces.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}()
.
sourceInterfaces.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.
sourceInterfaces.optional_keys
— Functionoptional_keys(T::Type{<:Interface}, O::Type)
Get the keys for the optional components of an Interface
, as a tuple os Symbol
.
sourceInterfaces.requiredtype
— Functionrequiredtype(::Type{<:Interface})
Returns the supertype required for all interface implementations.
sourceInterfaces.test
— Methodtest(m::Module)
+Arguments(nt::NamedTuple)
A wrapper for a NamedTuple
.
sourceInterfaces.Interface
— TypeInterface{Components}
Abstract supertype for all Interfaces.jl interfaces.
Components is an Tuple
of Symbol
.
sourceInterfaces.components
— Functioncomponents(::Type{<:Interface})
Returns the components of the interface, as a NamedTuple
of NamedTuple
.
sourceInterfaces.description
— Functiondescription(::Type{<:Interface})
Returns a String
description of an interface.
sourceInterfaces.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}()
.
sourceInterfaces.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.
sourceInterfaces.optional_keys
— Functionoptional_keys(T::Type{<:Interface}, O::Type)
Get the keys for the optional components of an Interface
, as a tuple os Symbol
.
sourceInterfaces.requiredtype
— Functionrequiredtype(::Type{<:Interface})
Returns the supertype required for all interface implementations.
sourceInterfaces.test
— Methodtest(m::Module)
test(::Type{<:Interface}, m::Module)
-test(::Type{<:Interface}, obj::Type)
Test if an interface is implemented correctly for an object, returning true
or false
.
If no interface type is passed, Interfaces.jl will find all the interfaces available and test them.
sourceInterfaces.test_objects
— Functiontest_objects(T::Type{<:Interface}, O::Type)
Get the test object(s) for type O
and interface T
.
sourceInterfaces.@implements
— Macro@implements(interface, objtype)
+test(::Type{<:Interface}, obj::Type)
Test if an interface is implemented correctly for an object, returning true
or false
.
If no interface type is passed, Interfaces.jl will find all the interfaces available and test them.
sourceInterfaces.test_objects
— Functiontest_objects(T::Type{<:Interface}, O::Type)
Get the test object(s) for type O
and interface T
.
sourceInterfaces.@implements
— Macro@implements(interface, objtype)
@implements(dev, interface, objtype)
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.
Passing the keyword dev
as the first argument lets us show test output during development. Do not use dev
in production code, or output will appear during package precompilation.
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
-@implements BaseInterfaces.IterationInterface{(:indexing,:reverse)} MyObject
sourceInterfaces.@interface
— Macro@interface(interfacename, components, [description])
Define an interface that can apply to types <: Any
.
components = (
+@implements BaseInterfaces.IterationInterface{(:indexing,:reverse)} MyObject
sourceInterfaces.@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)),
@@ -17,4 +17,4 @@
)
description = "A description of the interface"
-@interface MyInterface Any components description
sourceIndex
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
Settings
This document was generated with Documenter.jl version 1.1.2 on Thursday 2 November 2023. Using Julia version 1.9.3.
+@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