From 93efdb9e4e967a0ad0cb735721b0a67447cd12b2 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Tue, 16 Jul 2024 13:30:51 -0700 Subject: [PATCH] add doc-comments for the containment utilities --- Sources/Future/RawSpan.swift | 14 ++++++++++++++ Sources/Future/Span.swift | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Sources/Future/RawSpan.swift b/Sources/Future/RawSpan.swift index 8eac660a..4b1058b5 100644 --- a/Sources/Future/RawSpan.swift +++ b/Sources/Future/RawSpan.swift @@ -442,6 +442,12 @@ extension RawSpan { extension RawSpan { + /// Returns true if the memory represented by `span` is a subrange of + /// the memory represented by `self` + /// + /// Parameters: + /// - span: a span of the same type as `self` + /// Returns: whether `span` is a subrange of `self` @inlinable @inline(__always) public func contains(_ span: borrowing Self) -> Bool { if span._count > _count { return false } @@ -450,6 +456,14 @@ extension RawSpan { return span._start.advanced(by: span._count) <= _start.advanced(by: _count) } + /// Returns the offsets where the memory of `span` is located within + /// the memory represented by `self` + /// + /// Note: `span` must be a subrange of `self` + /// + /// Parameters: + /// - span: a subrange of `self` + /// Returns: A range of offsets within `self` @inlinable @inline(__always) public func offsets(of span: borrowing Self) -> Range { precondition(contains(span)) diff --git a/Sources/Future/Span.swift b/Sources/Future/Span.swift index f6258044..7f05fff9 100644 --- a/Sources/Future/Span.swift +++ b/Sources/Future/Span.swift @@ -653,6 +653,12 @@ extension Span where Element: Copyable { extension Span where Element: ~Copyable /*& ~Escapable*/ { + /// Returns true if the memory represented by `span` is a subrange of + /// the memory represented by `self` + /// + /// Parameters: + /// - span: a span of the same type as `self` + /// Returns: whether `span` is a subrange of `self` @inlinable @inline(__always) public func contains(_ span: borrowing Self) -> Bool { if span._count > _count { return false } @@ -661,6 +667,14 @@ extension Span where Element: ~Copyable /*& ~Escapable*/ { return span._start.advanced(by: span._count) <= _start.advanced(by: _count) } + /// Returns the offsets where the memory of `span` is located within + /// the memory represented by `self` + /// + /// Note: `span` must be a subrange of `self` + /// + /// Parameters: + /// - span: a subrange of `self` + /// Returns: A range of offsets within `self` @inlinable @inline(__always) public func offsets(of span: borrowing Self) -> Range { precondition(contains(span))