Skip to content

Commit

Permalink
Update the specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivor committed Oct 24, 2024
1 parent 2593c9b commit 274c06f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/meta_logger/slicer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ defmodule MetaLogger.Slicer do

@typedoc "Max length in bytes or `:infinity` if the entry should not be sliced."
@type max_entry_length :: non_neg_integer() | :infinity
@callback slice(String.t(), max_entry_length()) :: [String.t()]
@callback slice(binary(), max_entry_length()) :: [binary()]
end
1 change: 1 addition & 0 deletions lib/meta_logger/slicer/default_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule MetaLogger.Slicer.DefaultImpl do
"""
@impl MetaLogger.Slicer
@spec slice(binary(), MetaLogger.Slicer.max_entry_length()) :: [binary()]
def slice(entry, max_entry_length)
when max_entry_length == :infinity
when byte_size(entry) <= max_entry_length,
Expand Down
7 changes: 2 additions & 5 deletions lib/meta_logger/slicer/utf8_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ defmodule MetaLogger.Slicer.Utf8Impl do

@behaviour MetaLogger.Slicer

@typedoc "Max length in bytes or `:infinity` if the entry should not be sliced."
@type max_entry_length :: non_neg_integer() | :infinity

@doc """
Returns sliced log entries according to the given max entry length.
Expand All @@ -31,7 +28,7 @@ defmodule MetaLogger.Slicer.Utf8Impl do
["Hello ", "世界"]
"""
@impl MetaLogger.Slicer
@spec slice(String.t(), integer()) :: [String.t()]
@spec slice(binary(), MetaLogger.Slicer.max_entry_length()) :: [String.t()]
def slice(log_entry, :infinity), do: [log_entry]

def slice(entry, max_entry_length) when byte_size(entry) <= max_entry_length,
Expand All @@ -41,7 +38,7 @@ defmodule MetaLogger.Slicer.Utf8Impl do
do_slice(entry, max_entry_length, [], [], 0)
end

@spec do_slice(binary(), integer(), [binary()], [iodata()], integer()) :: [binary()]
@spec do_slice(binary(), integer(), [binary()], [iodata()], integer()) :: [String.t()]
defp do_slice(<<>>, _max_length, slices, partial_slice, _partial_size) do
# The remaining log entry is empty so we clean up the last partial_slice
# and return the slices.
Expand Down

0 comments on commit 274c06f

Please sign in to comment.