From 1ea5c627686b91a549da3ebee73170ac26915e4d Mon Sep 17 00:00:00 2001 From: Stavros Aronis Date: Fri, 4 Mar 2016 16:06:22 +0100 Subject: Add documentation about -specs for callbacks --- system/doc/design_principles/spec_proc.xml | 33 +++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'system/doc/design_principles/spec_proc.xml') diff --git a/system/doc/design_principles/spec_proc.xml b/system/doc/design_principles/spec_proc.xml index 3d7a88da3f..5b156ac263 100644 --- a/system/doc/design_principles/spec_proc.xml +++ b/system/doc/design_principles/spec_proc.xml @@ -4,7 +4,7 @@
- 19972014 + 19972016 Ericsson AB. All Rights Reserved. @@ -522,9 +522,36 @@ init(Parent, Name, Module) -> -module(db). -behaviour(simple_server). --export([init/0, handle_req/2, terminate/0]). +-export([init/1, handle_req/2, terminate/0]). ... + +

The contracts specified with -callback attributes in + behaviour modules can be further refined by adding -spec + attributes in callback modules. This can be useful as + -callback contracts are usually generic. The same callback + module with contracts for the callbacks:

+ + +-module(db). +-behaviour(simple_server). + +-export([init/1, handle_req/2, terminate/0]). + +-record(state, {field1 :: [atom()], field2 :: integer()}). + +-type state() :: #state{}. +-type request() :: {'store', term(), term()}; + {'lookup', term()}. + +... + +-spec handle_req(request(), state()) -> {'ok', term()}. + +... + +

Each -spec contract is to be a subtype of the respective + -callback contract.

+ - -- cgit v1.2.3