Erlang'记录'的解释

ant*_*eal 4 erlang records double-quotes

我在这里探索源代码:

https://github.com/s1n4/leptus/blob/master/include/leptus_logger.hrl

并注意到这样定义的记录:

-record(log_data,
    {
      request_time = erlang:localtime() :: calendar:datetime(),
      response_time :: undefined | calendar:datetime(),
      request_line = "" :: string(),
      ip :: inet:ip_address(),
      version = 'HTTP/1.1' :: atom(),
      method = <<"GET">> :: binary(),
      uri = <<"/">> :: binary(),
      headers = [] :: [{binary(), iodata()}],
      status = 200 :: non_neg_integer(),
      content_length = 0 :: non_neg_integer()
    }).
Run Code Online (Sandbox Code Playgroud)

我只知道列表推导和类型中使用的"双冒号".从来没有发现任何关于记录的事 搜索也没有帮助.我把它解释为:

'request_time' is 'erlang:local time()' of type 'calendar:date time()'
response_time is of type undefined or calendar:datetime
and so on ...
Run Code Online (Sandbox Code Playgroud)

它是否正确 ?

zxq*_*xq9 10

是的,你是对的.您可以在记录定义中包含类型信息.实际上,这是记录中最酷的一个方面,而且我很少使用.

您正在查找的文档的部分是一个有点难以找到,但它记载:

http://www.erlang.org/doc/reference_manual/typespec.html#typeinrecords