pw_span: Switch from pw::span to std::span

Replace pw::span with std::span and "pw_span/span.h" with <span>
throughout the codebase.

Change-Id: Ib1fa873168b6093794e861611d750fcad6285d6c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/12801
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
diff --git a/pw_kvs/public/pw_kvs/alignment.h b/pw_kvs/public/pw_kvs/alignment.h
index f153756..e8cf191 100644
--- a/pw_kvs/public/pw_kvs/alignment.h
+++ b/pw_kvs/public/pw_kvs/alignment.h
@@ -17,10 +17,10 @@
 #include <cstddef>
 #include <cstring>
 #include <initializer_list>
+#include <span>
 #include <utility>
 
 #include "pw_kvs/io.h"
-#include "pw_span/span.h"
 #include "pw_status/status_with_size.h"
 
 namespace pw {
@@ -46,7 +46,9 @@
 // called or the AlignedWriter goes out of scope.
 class AlignedWriter {
  public:
-  AlignedWriter(span<std::byte> buffer, size_t alignment_bytes, Output& writer)
+  AlignedWriter(std::span<std::byte> buffer,
+                size_t alignment_bytes,
+                Output& writer)
       : buffer_(buffer.data()),
         write_size_(AlignDown(buffer.size(), alignment_bytes)),
         alignment_bytes_(alignment_bytes),
@@ -66,10 +68,10 @@
   // successful and failed Write calls. On a failed write call, knowing the
   // bytes attempted may be important when working with flash memory, since it
   // can only be written once between erases.
-  StatusWithSize Write(span<const std::byte> data);
+  StatusWithSize Write(std::span<const std::byte> data);
 
   StatusWithSize Write(const void* data, size_t size) {
-    return Write(span(static_cast<const std::byte*>(data), size));
+    return Write(std::span(static_cast<const std::byte*>(data), size));
   }
 
   // Reads size bytes from the input and writes them to the output.
@@ -110,7 +112,7 @@
 template <size_t kBufferSize>
 StatusWithSize AlignedWrite(Output& output,
                             size_t alignment_bytes,
-                            span<const span<const std::byte>> data) {
+                            std::span<const std::span<const std::byte>> data) {
   // TODO: This should convert to PW_CHECK once that is available for use in
   // host tests.
   if (alignment_bytes > kBufferSize) {
@@ -119,7 +121,7 @@
 
   AlignedWriterBuffer<kBufferSize> buffer(alignment_bytes, output);
 
-  for (const span<const std::byte>& chunk : data) {
+  for (const std::span<const std::byte>& chunk : data) {
     if (StatusWithSize result = buffer.Write(chunk); !result.ok()) {
       return result;
     }
@@ -130,11 +132,12 @@
 
 // Calls AlignedWrite with an initializer list.
 template <size_t kBufferSize>
-StatusWithSize AlignedWrite(Output& output,
-                            size_t alignment_bytes,
-                            std::initializer_list<span<const std::byte>> data) {
+StatusWithSize AlignedWrite(
+    Output& output,
+    size_t alignment_bytes,
+    std::initializer_list<std::span<const std::byte>> data) {
   return AlignedWrite<kBufferSize>(
-      output, alignment_bytes, span(data.begin(), data.size()));
+      output, alignment_bytes, std::span(data.begin(), data.size()));
 }
 
 }  // namespace pw
diff --git a/pw_kvs/public/pw_kvs/checksum.h b/pw_kvs/public/pw_kvs/checksum.h
index ff89d44..5899566 100644
--- a/pw_kvs/public/pw_kvs/checksum.h
+++ b/pw_kvs/public/pw_kvs/checksum.h
@@ -14,9 +14,9 @@
 #pragma once
 
 #include <cstddef>
+#include <span>
 
 #include "pw_kvs/alignment.h"
-#include "pw_span/span.h"
 #include "pw_status/status.h"
 
 namespace pw::kvs {
@@ -27,18 +27,18 @@
   virtual void Reset() = 0;
 
   // Updates the checksum with the provided data.
-  virtual void Update(span<const std::byte> data) = 0;
+  virtual void Update(std::span<const std::byte> data) = 0;
 
   // Updates the checksum from a pointer and size.
   void Update(const void* data, size_t size_bytes) {
-    return Update(span(static_cast<const std::byte*>(data), size_bytes));
+    return Update(std::span(static_cast<const std::byte*>(data), size_bytes));
   }
 
   // Returns the final result of the checksum. Update() can no longer be called
-  // after this. The returned span is valid until a call to Reset().
+  // after this. The returned std::span is valid until a call to Reset().
   //
   // Finish MUST be called before calling Verify.
-  span<const std::byte> Finish() {
+  std::span<const std::byte> Finish() {
     Finalize();  // Implemented by derived classes, if required.
     return state();
   }
@@ -51,24 +51,25 @@
   // size_bytes() are ignored.
   //
   // Finish MUST be called before calling Verify.
-  Status Verify(span<const std::byte> checksum) const;
+  Status Verify(std::span<const std::byte> checksum) const;
 
  protected:
-  // A derived class provides a span of its state buffer.
-  constexpr ChecksumAlgorithm(span<const std::byte> state) : state_(state) {}
+  // A derived class provides a std::span of its state buffer.
+  constexpr ChecksumAlgorithm(std::span<const std::byte> state)
+      : state_(state) {}
 
   // Protected destructor prevents deleting ChecksumAlgorithms from the base
   // class, so that it is safe to have a non-virtual destructor.
   ~ChecksumAlgorithm() = default;
 
   // Returns the current checksum state.
-  constexpr span<const std::byte> state() const { return state_; }
+  constexpr std::span<const std::byte> state() const { return state_; }
 
  private:
   // Checksums that require finalizing operations may override this method.
   virtual void Finalize() {}
 
-  span<const std::byte> state_;
+  std::span<const std::byte> state_;
 };
 
 // A checksum algorithm for which Verify always passes. This can be used to
@@ -78,7 +79,7 @@
   constexpr IgnoreChecksum() : ChecksumAlgorithm({}) {}
 
   void Reset() override {}
-  void Update(span<const std::byte>) override {}
+  void Update(std::span<const std::byte>) override {}
 };
 
 // Calculates a checksum in kAlignmentBytes chunks. Checksum classes can inherit
@@ -87,10 +88,10 @@
 template <size_t kAlignmentBytes, size_t kBufferSize = kAlignmentBytes>
 class AlignedChecksum : public ChecksumAlgorithm {
  public:
-  void Update(span<const std::byte> data) final { writer_.Write(data); }
+  void Update(std::span<const std::byte> data) final { writer_.Write(data); }
 
  protected:
-  constexpr AlignedChecksum(span<const std::byte> state)
+  constexpr AlignedChecksum(std::span<const std::byte> state)
       : ChecksumAlgorithm(state),
         output_(this),
         writer_(kAlignmentBytes, output_) {}
@@ -105,7 +106,7 @@
     FinalizeAligned();
   }
 
-  virtual void UpdateAligned(span<const std::byte> data) = 0;
+  virtual void UpdateAligned(std::span<const std::byte> data) = 0;
 
   virtual void FinalizeAligned() = 0;
 
diff --git a/pw_kvs/public/pw_kvs/crc16_checksum.h b/pw_kvs/public/pw_kvs/crc16_checksum.h
index 51b096b..6cbef1f 100644
--- a/pw_kvs/public/pw_kvs/crc16_checksum.h
+++ b/pw_kvs/public/pw_kvs/crc16_checksum.h
@@ -13,19 +13,20 @@
 // the License.
 #pragma once
 
+#include <span>
+
 #include "pw_checksum/ccitt_crc16.h"
 #include "pw_kvs/checksum.h"
-#include "pw_span/span.h"
 
 namespace pw::kvs {
 
 class ChecksumCrc16 final : public ChecksumAlgorithm {
  public:
-  ChecksumCrc16() : ChecksumAlgorithm(as_bytes(span(&crc_, 1))) {}
+  ChecksumCrc16() : ChecksumAlgorithm(std::as_bytes(std::span(&crc_, 1))) {}
 
   void Reset() override { crc_ = checksum::kCcittCrc16DefaultInitialValue; }
 
-  void Update(span<const std::byte> data) override {
+  void Update(std::span<const std::byte> data) override {
     crc_ = checksum::CcittCrc16(data, crc_);
   }
 
diff --git a/pw_kvs/public/pw_kvs/fake_flash_memory.h b/pw_kvs/public/pw_kvs/fake_flash_memory.h
index a0916bf..5dc839c 100644
--- a/pw_kvs/public/pw_kvs/fake_flash_memory.h
+++ b/pw_kvs/public/pw_kvs/fake_flash_memory.h
@@ -17,10 +17,10 @@
 #include <array>
 #include <cstddef>
 #include <cstring>
+#include <span>
 
 #include "pw_containers/vector.h"
 #include "pw_kvs/flash_memory.h"
-#include "pw_span/span.h"
 #include "pw_status/status.h"
 
 namespace pw::kvs {
@@ -50,7 +50,7 @@
   Status Check(FlashMemory::Address start_address, size_t size);
 
   // Determines if any of a series of FlashErrors applies to the operation.
-  static Status Check(span<FlashError> errors,
+  static Status Check(std::span<FlashError> errors,
                       FlashMemory::Address address,
                       size_t size);
 
@@ -88,7 +88,7 @@
 
   static constexpr std::byte kErasedValue = std::byte{0xff};
 
-  FakeFlashMemory(span<std::byte> buffer,
+  FakeFlashMemory(std::span<std::byte> buffer,
                   size_t sector_size,
                   size_t sector_count,
                   size_t alignment_bytes = kDefaultAlignmentBytes,
@@ -110,16 +110,17 @@
   Status Erase(Address address, size_t num_sectors) override;
 
   // Reads bytes from flash into buffer.
-  StatusWithSize Read(Address address, span<std::byte> output) override;
+  StatusWithSize Read(Address address, std::span<std::byte> output) override;
 
   // Writes bytes to flash.
-  StatusWithSize Write(Address address, span<const std::byte> data) override;
+  StatusWithSize Write(Address address,
+                       std::span<const std::byte> data) override;
 
   // Testing API
 
   // Access the underlying buffer for testing purposes. Not part of the
   // FlashMemory API.
-  span<std::byte> buffer() const { return buffer_; }
+  std::span<std::byte> buffer() const { return buffer_; }
 
   bool InjectReadError(const FlashError& error) {
     if (read_errors_.full()) {
@@ -138,7 +139,7 @@
   }
 
  private:
-  const span<std::byte> buffer_;
+  const std::span<std::byte> buffer_;
   Vector<FlashError>& read_errors_;
   Vector<FlashError>& write_errors_;
 };
@@ -156,7 +157,7 @@
 
   // Creates a flash memory initialized to the provided contents.
   explicit FakeFlashMemoryBuffer(
-      span<const std::byte> contents,
+      std::span<const std::byte> contents,
       size_t alignment_bytes = kDefaultAlignmentBytes)
       : FakeFlashMemory(buffer_,
                         kSectorSize,
diff --git a/pw_kvs/public/pw_kvs/flash_memory.h b/pw_kvs/public/pw_kvs/flash_memory.h
index b284415..ac8f429 100644
--- a/pw_kvs/public/pw_kvs/flash_memory.h
+++ b/pw_kvs/public/pw_kvs/flash_memory.h
@@ -16,9 +16,9 @@
 #include <cstddef>
 #include <cstdint>
 #include <initializer_list>
+#include <span>
 
 #include "pw_kvs/alignment.h"
-#include "pw_span/span.h"
 #include "pw_status/status.h"
 #include "pw_status/status_with_size.h"
 
@@ -71,10 +71,10 @@
   //                OK: success
   // DEADLINE_EXCEEDED: timeout
   //      OUT_OF_RANGE: write does not fit in the flash memory
-  virtual StatusWithSize Read(Address address, span<std::byte> output) = 0;
+  virtual StatusWithSize Read(Address address, std::span<std::byte> output) = 0;
 
   StatusWithSize Read(Address address, void* buffer, size_t len) {
-    return Read(address, span(static_cast<std::byte*>(buffer), len));
+    return Read(address, std::span(static_cast<std::byte*>(buffer), len));
   }
 
   // Writes bytes to flash. Blocking call.
@@ -85,13 +85,13 @@
   //      OUT_OF_RANGE: write does not fit in the memory
   //
   virtual StatusWithSize Write(Address destination_flash_address,
-                               span<const std::byte> data) = 0;
+                               std::span<const std::byte> data) = 0;
 
   StatusWithSize Write(Address destination_flash_address,
                        const void* data,
                        size_t len) {
     return Write(destination_flash_address,
-                 span(static_cast<const std::byte*>(data), len));
+                 std::span(static_cast<const std::byte*>(data), len));
   }
 
   // Convert an Address to an MCU pointer, this can be used for memory
@@ -135,7 +135,7 @@
         : flash_(flash), address_(address) {}
 
    private:
-    StatusWithSize DoWrite(span<const std::byte> data) override;
+    StatusWithSize DoWrite(std::span<const std::byte> data) override;
 
     FlashPartition& flash_;
     FlashPartition::Address address_;
@@ -148,7 +148,7 @@
         : flash_(flash), address_(address) {}
 
    private:
-    StatusWithSize DoRead(span<std::byte> data) override;
+    StatusWithSize DoRead(std::span<std::byte> data) override;
 
     FlashPartition& flash_;
     FlashPartition::Address address_;
@@ -196,10 +196,10 @@
   //          TIMEOUT, on timeout.
   //          INVALID_ARGUMENT, if address or length is invalid.
   //          UNKNOWN, on HAL error
-  virtual StatusWithSize Read(Address address, span<std::byte> output);
+  virtual StatusWithSize Read(Address address, std::span<std::byte> output);
 
   StatusWithSize Read(Address address, size_t length, void* output) {
-    return Read(address, span(static_cast<std::byte*>(output), length));
+    return Read(address, std::span(static_cast<std::byte*>(output), length));
   }
 
   // Writes bytes to flash. Blocking call.
@@ -208,7 +208,8 @@
   //          INVALID_ARGUMENT, if address or length is invalid.
   //          PERMISSION_DENIED, if partition is read only.
   //          UNKNOWN, on HAL error
-  virtual StatusWithSize Write(Address address, span<const std::byte> data);
+  virtual StatusWithSize Write(Address address,
+                               std::span<const std::byte> data);
 
   // Check to see if chunk of flash memory is erased. Address and len need to
   // be aligned with FlashMemory.
@@ -224,7 +225,7 @@
   // Checks to see if the data appears to be erased. No reads or writes occur;
   // the FlashPartition simply compares the data to
   // flash_.erased_memory_content().
-  bool AppearsErased(span<const std::byte> data) const;
+  bool AppearsErased(std::span<const std::byte> data) const;
 
   // Overridden by derived classes. The reported sector size is space available
   // to users of FlashPartition. It accounts for space reserved in the sector
diff --git a/pw_kvs/public/pw_kvs/flash_partition_with_stats.h b/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
index 9393fd9..569ab9f 100644
--- a/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
+++ b/pw_kvs/public/pw_kvs/flash_partition_with_stats.h
@@ -38,8 +38,8 @@
 
   Status Erase(Address address, size_t num_sectors) override;
 
-  span<size_t> sector_erase_counters() {
-    return span(sector_counters_.data(), sector_counters_.size());
+  std::span<size_t> sector_erase_counters() {
+    return std::span(sector_counters_.data(), sector_counters_.size());
   }
 
   size_t min_erase_count() const {
diff --git a/pw_kvs/public/pw_kvs/format.h b/pw_kvs/public/pw_kvs/format.h
index a2d843a..f6b33e7 100644
--- a/pw_kvs/public/pw_kvs/format.h
+++ b/pw_kvs/public/pw_kvs/format.h
@@ -14,9 +14,9 @@
 #pragma once
 
 #include <cstdint>
+#include <span>
 
 #include "pw_kvs/checksum.h"
-#include "pw_span/span.h"
 
 namespace pw::kvs {
 
@@ -56,7 +56,7 @@
 // simultaneously supported formats.
 class EntryFormats {
  public:
-  explicit constexpr EntryFormats(span<const EntryFormat> formats)
+  explicit constexpr EntryFormats(std::span<const EntryFormat> formats)
       : formats_(formats) {}
 
   explicit constexpr EntryFormats(const EntryFormat& format)
@@ -69,7 +69,7 @@
   const EntryFormat* Find(uint32_t magic) const;
 
  private:
-  const span<const EntryFormat> formats_;
+  const std::span<const EntryFormat> formats_;
 };
 
 }  // namespace internal
diff --git a/pw_kvs/public/pw_kvs/internal/entry.h b/pw_kvs/public/pw_kvs/internal/entry.h
index 3e75aeb..5305ab6 100644
--- a/pw_kvs/public/pw_kvs/internal/entry.h
+++ b/pw_kvs/public/pw_kvs/internal/entry.h
@@ -19,6 +19,7 @@
 #include <array>
 #include <cstddef>
 #include <cstdint>
+#include <span>
 #include <string_view>
 
 #include "pw_kvs/alignment.h"
@@ -27,7 +28,6 @@
 #include "pw_kvs/format.h"
 #include "pw_kvs/internal/hash.h"
 #include "pw_kvs/internal/key_descriptor.h"
-#include "pw_span/span.h"
 
 namespace pw::kvs::internal {
 
@@ -64,7 +64,7 @@
                      Address address,
                      const EntryFormat& format,
                      std::string_view key,
-                     span<const std::byte> value,
+                     std::span<const std::byte> value,
                      uint32_t transaction_id) {
     return Entry(
         partition, address, format, key, value, value.size(), transaction_id);
@@ -97,7 +97,8 @@
                          deleted() ? EntryState::kDeleted : EntryState::kValid};
   }
 
-  StatusWithSize Write(std::string_view key, span<const std::byte> value) const;
+  StatusWithSize Write(std::string_view key,
+                       std::span<const std::byte> value) const;
 
   // Changes the format and transcation ID for this entry. In order to calculate
   // the new checksum, the entire entry is read into a small stack-allocated
@@ -119,20 +120,20 @@
         ReadKey(partition(), address_, key_length(), key.data()), key_length());
   }
 
-  StatusWithSize ReadValue(span<std::byte> buffer,
+  StatusWithSize ReadValue(std::span<std::byte> buffer,
                            size_t offset_bytes = 0) const;
 
-  Status ValueMatches(span<const std::byte> value) const;
+  Status ValueMatches(std::span<const std::byte> value) const;
 
   Status VerifyChecksum(std::string_view key,
-                        span<const std::byte> value) const;
+                        std::span<const std::byte> value) const;
 
   Status VerifyChecksumInFlash() const;
 
   // Calculates the total size of an entry, including padding.
   static size_t size(const FlashPartition& partition,
                      std::string_view key,
-                     span<const std::byte> value) {
+                     std::span<const std::byte> value) {
     return AlignUp(sizeof(EntryHeader) + key.size() + value.size(),
                    std::max(partition.alignment_bytes(), kMinAlignmentBytes));
   }
@@ -174,7 +175,7 @@
         Address address,
         const EntryFormat& format,
         std::string_view key,
-        span<const std::byte> value,
+        std::span<const std::byte> value,
         uint16_t value_size_bytes,
         uint32_t transaction_id);
 
@@ -196,12 +197,12 @@
     return sizeof(EntryHeader) + key_length() + value_size();
   }
 
-  span<const std::byte> checksum_bytes() const {
-    return as_bytes(span(&header_.checksum, 1));
+  std::span<const std::byte> checksum_bytes() const {
+    return std::as_bytes(std::span(&header_.checksum, 1));
   }
 
-  span<const std::byte> CalculateChecksum(std::string_view key,
-                                          span<const std::byte> value) const;
+  std::span<const std::byte> CalculateChecksum(
+      std::string_view key, std::span<const std::byte> value) const;
 
   Status CalculateChecksumFromFlash();
 
diff --git a/pw_kvs/public/pw_kvs/internal/entry_cache.h b/pw_kvs/public/pw_kvs/internal/entry_cache.h
index 5ed2f15..f347738 100644
--- a/pw_kvs/public/pw_kvs/internal/entry_cache.h
+++ b/pw_kvs/public/pw_kvs/internal/entry_cache.h
@@ -15,6 +15,7 @@
 
 #include <cstddef>
 #include <cstdint>
+#include <span>
 #include <string_view>
 #include <type_traits>
 
@@ -23,7 +24,6 @@
 #include "pw_kvs/format.h"
 #include "pw_kvs/internal/key_descriptor.h"
 #include "pw_kvs/internal/sectors.h"
-#include "pw_span/span.h"
 
 namespace pw::kvs::internal {
 
@@ -45,7 +45,7 @@
   uint32_t first_address() const { return addresses_[0]; }
 
   // All addresses for this entry, including redundant entries, if any.
-  const span<Address>& addresses() const { return addresses_; }
+  const std::span<Address>& addresses() const { return addresses_; }
 
   // True if the KeyDesctiptor's transaction ID is newer than the specified ID.
   bool IsNewerThan(uint32_t other_transaction_id) const {
@@ -57,7 +57,7 @@
   // than allowed by the redundancy.
   void AddNewAddress(Address address) {
     addresses_[addresses_.size()] = address;
-    addresses_ = span(addresses_.begin(), addresses_.size() + 1);
+    addresses_ = std::span(addresses_.begin(), addresses_.size() + 1);
   }
 
   // Remove an address from the entry metadata.
@@ -70,11 +70,12 @@
  private:
   friend class EntryCache;
 
-  constexpr EntryMetadata(KeyDescriptor& descriptor, span<Address> addresses)
+  constexpr EntryMetadata(KeyDescriptor& descriptor,
+                          std::span<Address> addresses)
       : descriptor_(&descriptor), addresses_(addresses) {}
 
   KeyDescriptor* descriptor_;
-  span<Address> addresses_;
+  std::span<Address> addresses_;
 };
 
 // Tracks entry metadata. Combines KeyDescriptors and with their associated
@@ -215,8 +216,8 @@
   // address slot available.
   void AddAddressIfRoom(size_t descriptor_index, Address address) const;
 
-  // Returns a span of the valid addresses for the descriptor.
-  span<Address> addresses(size_t descriptor_index) const;
+  // Returns a std::span of the valid addresses for the descriptor.
+  std::span<Address> addresses(size_t descriptor_index) const;
 
   Address* first_address(size_t descriptor_index) const {
     return &addresses_[descriptor_index * redundancy_];
diff --git a/pw_kvs/public/pw_kvs/internal/sectors.h b/pw_kvs/public/pw_kvs/internal/sectors.h
index 7f89bb5..d2f4565 100644
--- a/pw_kvs/public/pw_kvs/internal/sectors.h
+++ b/pw_kvs/public/pw_kvs/internal/sectors.h
@@ -16,10 +16,10 @@
 #include <climits>
 #include <cstddef>
 #include <cstdint>
+#include <span>
 
 #include "pw_containers/vector.h"
 #include "pw_kvs/flash_memory.h"
-#include "pw_span/span.h"
 
 namespace pw::kvs::internal {
 
@@ -159,7 +159,7 @@
   // least 1 empty sector. Addresses in reserved_addresses are avoided.
   Status FindSpace(SectorDescriptor** found_sector,
                    size_t size,
-                   span<const Address> reserved_addresses) {
+                   std::span<const Address> reserved_addresses) {
     return Find(kAppendEntry, found_sector, size, {}, reserved_addresses);
   }
 
@@ -168,8 +168,8 @@
   Status FindSpaceDuringGarbageCollection(
       SectorDescriptor** found_sector,
       size_t size,
-      span<const Address> addresses_to_skip,
-      span<const Address> reserved_addresses) {
+      std::span<const Address> addresses_to_skip,
+      std::span<const Address> reserved_addresses) {
     return Find(kGarbageCollect,
                 found_sector,
                 size,
@@ -180,7 +180,7 @@
   // Finds a sector that is ready to be garbage collected. Returns nullptr if no
   // sectors can / need to be garbage collected.
   SectorDescriptor* FindSectorToGarbageCollect(
-      span<const Address> addresses_to_avoid) const;
+      std::span<const Address> addresses_to_avoid) const;
 
   // The number of sectors in use.
   size_t size() const { return descriptors_.size(); }
@@ -210,8 +210,8 @@
   Status Find(FindMode find_mode,
               SectorDescriptor** found_sector,
               size_t size,
-              span<const Address> addresses_to_skip,
-              span<const Address> reserved_addresses);
+              std::span<const Address> addresses_to_skip,
+              std::span<const Address> reserved_addresses);
 
   SectorDescriptor& WearLeveledSectorFromIndex(size_t idx) const;
 
diff --git a/pw_kvs/public/pw_kvs/internal/span_traits.h b/pw_kvs/public/pw_kvs/internal/span_traits.h
index 18098ed..4c4ab56 100644
--- a/pw_kvs/public/pw_kvs/internal/span_traits.h
+++ b/pw_kvs/public/pw_kvs/internal/span_traits.h
@@ -18,12 +18,13 @@
 namespace pw::kvs {
 
 namespace internal {
-template <typename T, typename = decltype(span(std::declval<T>()))>
+template <typename T, typename = decltype(std::span(std::declval<T>()))>
 constexpr bool ConvertsToSpan(int) {
   return true;
 }
 
-// If the expression span(T) fails, then the type can't be converted to a span.
+// If the expression std::span(T) fails, then the type can't be converted to a
+// std::span.
 template <typename T>
 constexpr bool ConvertsToSpan(...) {
   return false;
@@ -31,7 +32,7 @@
 
 }  // namespace internal
 
-// Traits class to detect if the type converts to a span.
+// Traits class to detect if the type converts to a std::span.
 template <typename T>
 struct ConvertsToSpan
     : public std::bool_constant<
diff --git a/pw_kvs/public/pw_kvs/io.h b/pw_kvs/public/pw_kvs/io.h
index 71d1eb2..167182f 100644
--- a/pw_kvs/public/pw_kvs/io.h
+++ b/pw_kvs/public/pw_kvs/io.h
@@ -14,9 +14,9 @@
 #pragma once
 
 #include <cstddef>
+#include <span>
 #include <type_traits>
 
-#include "pw_span/span.h"
 #include "pw_status/status_with_size.h"
 
 namespace pw {
@@ -34,41 +34,43 @@
 }  // namespace internal
 
 // Writes bytes to an unspecified output. Provides a Write function that takes a
-// span of bytes and returns a Status.
+// std::span of bytes and returns a Status.
 class Output {
  public:
-  StatusWithSize Write(span<const std::byte> data) { return DoWrite(data); }
+  StatusWithSize Write(std::span<const std::byte> data) {
+    return DoWrite(data);
+  }
 
   // Convenience wrapper for writing data from a pointer and length.
   StatusWithSize Write(const void* data, size_t size_bytes) {
-    return Write(span(static_cast<const std::byte*>(data), size_bytes));
+    return Write(std::span(static_cast<const std::byte*>(data), size_bytes));
   }
 
  protected:
   ~Output() = default;
 
  private:
-  virtual StatusWithSize DoWrite(span<const std::byte> data) = 0;
+  virtual StatusWithSize DoWrite(std::span<const std::byte> data) = 0;
 };
 
 class Input {
  public:
-  StatusWithSize Read(span<std::byte> data) { return DoRead(data); }
+  StatusWithSize Read(std::span<std::byte> data) { return DoRead(data); }
 
   // Convenience wrapper for reading data from a pointer and length.
   StatusWithSize Read(void* data, size_t size_bytes) {
-    return Read(span(static_cast<std::byte*>(data), size_bytes));
+    return Read(std::span(static_cast<std::byte*>(data), size_bytes));
   }
 
  protected:
   ~Input() = default;
 
  private:
-  virtual StatusWithSize DoRead(span<std::byte> data) = 0;
+  virtual StatusWithSize DoRead(std::span<std::byte> data) = 0;
 };
 
-// Output adapter that calls a method on a class with a span of bytes. If the
-// method returns void instead of the expected Status, Write always returns
+// Output adapter that calls a method on a class with a std::span of bytes. If
+// the method returns void instead of the expected Status, Write always returns
 // Status::OK.
 template <auto kMethod>
 class OutputToMethod final : public Output {
@@ -78,7 +80,7 @@
   constexpr OutputToMethod(Class* object) : object_(*object) {}
 
  private:
-  StatusWithSize DoWrite(span<const std::byte> data) override {
+  StatusWithSize DoWrite(std::span<const std::byte> data) override {
     using Return = typename internal::FunctionTraits<decltype(kMethod)>::Return;
 
     if constexpr (std::is_void_v<Return>) {
@@ -96,15 +98,15 @@
 // Output adapter that calls a free function.
 class OutputToFunction final : public Output {
  public:
-  OutputToFunction(StatusWithSize (*function)(span<const std::byte>))
+  OutputToFunction(StatusWithSize (*function)(std::span<const std::byte>))
       : function_(function) {}
 
  private:
-  StatusWithSize DoWrite(span<const std::byte> data) override {
+  StatusWithSize DoWrite(std::span<const std::byte> data) override {
     return function_(data);
   }
 
-  StatusWithSize (*function_)(span<const std::byte>);
+  StatusWithSize (*function_)(std::span<const std::byte>);
 };
 
 }  // namespace pw
diff --git a/pw_kvs/public/pw_kvs/key_value_store.h b/pw_kvs/public/pw_kvs/key_value_store.h
index f382c60..01b055d 100644
--- a/pw_kvs/public/pw_kvs/key_value_store.h
+++ b/pw_kvs/public/pw_kvs/key_value_store.h
@@ -16,6 +16,7 @@
 #include <array>
 #include <cstddef>
 #include <cstdint>
+#include <span>
 #include <string_view>
 #include <type_traits>
 
@@ -28,7 +29,6 @@
 #include "pw_kvs/internal/key_descriptor.h"
 #include "pw_kvs/internal/sectors.h"
 #include "pw_kvs/internal/span_traits.h"
-#include "pw_span/span.h"
 #include "pw_status/status.h"
 #include "pw_status/status_with_size.h"
 
@@ -116,12 +116,13 @@
   //      INVALID_ARGUMENT: key is empty or too long or value is too large
   //
   StatusWithSize Get(std::string_view key,
-                     span<std::byte> value,
+                     std::span<std::byte> value,
                      size_t offset_bytes = 0) const;
 
   // This overload of Get accepts a pointer to a trivially copyable object.
-  // If the value is an array, call Get with as_writable_bytes(span(array)),
-  // or pass a pointer to the array instead of the array itself.
+  // If the value is an array, call Get with
+  // std::as_writable_bytes(std::span(array)), or pass a pointer to the array
+  // instead of the array itself.
   template <typename Pointer,
             typename = std::enable_if_t<std::is_pointer_v<Pointer>>>
   Status Get(const std::string_view& key, const Pointer& pointer) const {
@@ -133,7 +134,7 @@
   // Adds a key-value entry to the KVS. If the key was already present, its
   // value is overwritten.
   //
-  // The value may be a span of bytes or a trivially copyable object.
+  // The value may be a std::span of bytes or a trivially copyable object.
   //
   // In the current implementation, all keys in the KVS must have a unique hash.
   // If Put is called with a key whose hash matches an existing key, nothing
@@ -150,10 +151,10 @@
   template <typename T>
   Status Put(const std::string_view& key, const T& value) {
     if constexpr (ConvertsToSpan<T>::value) {
-      return PutBytes(key, as_bytes(span(value)));
+      return PutBytes(key, std::as_bytes(std::span(value)));
     } else {
       CheckThatObjectCanBePutOrGet<T>();
-      return PutBytes(key, as_bytes(span(&value, 1)));
+      return PutBytes(key, std::as_bytes(std::span(&value, 1)));
     }
   }
 
@@ -202,7 +203,7 @@
 
     // Gets the value referred to by this iterator. Equivalent to
     // KeyValueStore::Get.
-    StatusWithSize Get(span<std::byte> value_buffer,
+    StatusWithSize Get(std::span<std::byte> value_buffer,
                        size_t offset_bytes = 0) const {
       return kvs_.Get(key(), *iterator_, value_buffer, offset_bytes);
     }
@@ -315,7 +316,7 @@
   // In the future, will be able to provide additional EntryFormats for
   // backwards compatibility.
   KeyValueStore(FlashPartition* partition,
-                span<const EntryFormat> formats,
+                std::span<const EntryFormat> formats,
                 const Options& options,
                 size_t redundancy,
                 Vector<SectorDescriptor>& sector_descriptor_list,
@@ -332,8 +333,9 @@
     static_assert(
         std::is_trivially_copyable_v<T> && !std::is_pointer_v<T>,
         "Only trivially copyable, non-pointer objects may be Put and Get by "
-        "value. Any value may be stored by converting it to a byte span with "
-        "as_bytes(span(&value, 1)) or as_writable_bytes(span(&value, 1)).");
+        "value. Any value may be stored by converting it to a byte std::span "
+        "with std::as_bytes(std::span(&value, 1)) or "
+        "std::as_writable_bytes(std::span(&value, 1)).");
   }
 
   Status InitializeMetadata();
@@ -342,7 +344,7 @@
                       Address start_address,
                       Address* next_entry_address);
 
-  Status PutBytes(std::string_view key, span<const std::byte> value);
+  Status PutBytes(std::string_view key, std::span<const std::byte> value);
 
   StatusWithSize ValueSize(const EntryMetadata& metadata) const;
 
@@ -372,7 +374,7 @@
 
   StatusWithSize Get(std::string_view key,
                      const EntryMetadata& metadata,
-                     span<std::byte> value_buffer,
+                     std::span<std::byte> value_buffer,
                      size_t offset_bytes) const;
 
   Status FixedSizeGet(std::string_view key,
@@ -390,12 +392,13 @@
   Status WriteEntryForExistingKey(EntryMetadata& metadata,
                                   EntryState new_state,
                                   std::string_view key,
-                                  span<const std::byte> value);
+                                  std::span<const std::byte> value);
 
-  Status WriteEntryForNewKey(std::string_view key, span<const std::byte> value);
+  Status WriteEntryForNewKey(std::string_view key,
+                             std::span<const std::byte> value);
 
   Status WriteEntry(std::string_view key,
-                    span<const std::byte> value,
+                    std::span<const std::byte> value,
                     EntryState new_state,
                     EntryMetadata* prior_metadata = nullptr,
                     const internal::Entry* prior_entry = nullptr);
@@ -414,13 +417,13 @@
 
   Status GetSectorForWrite(SectorDescriptor** sector,
                            size_t entry_size,
-                           span<const Address> addresses_to_skip);
+                           std::span<const Address> addresses_to_skip);
 
   Status MarkSectorCorruptIfNotOk(Status status, SectorDescriptor* sector);
 
   Status AppendEntry(const Entry& entry,
                      std::string_view key,
-                     span<const std::byte> value);
+                     std::span<const std::byte> value);
 
   StatusWithSize CopyEntryToSector(Entry& entry,
                                    SectorDescriptor* new_sector,
@@ -428,18 +431,19 @@
 
   Status RelocateEntry(const EntryMetadata& metadata,
                        KeyValueStore::Address& address,
-                       span<const Address> addresses_to_skip);
+                       std::span<const Address> addresses_to_skip);
 
   // Find and garbage collect a singe sector that does not include an address to
   // skip.
-  Status GarbageCollect(span<const Address> addresses_to_skip);
+  Status GarbageCollect(std::span<const Address> addresses_to_skip);
 
-  Status RelocateKeyAddressesInSector(SectorDescriptor& sector_to_gc,
-                                      const EntryMetadata& descriptor,
-                                      span<const Address> addresses_to_skip);
+  Status RelocateKeyAddressesInSector(
+      SectorDescriptor& sector_to_gc,
+      const EntryMetadata& descriptor,
+      std::span<const Address> addresses_to_skip);
 
   Status GarbageCollectSector(SectorDescriptor& sector_to_gc,
-                              span<const Address> addresses_to_skip);
+                              std::span<const Address> addresses_to_skip);
 
   // Ensure that all entries are on the primary (first) format. Entries that are
   // not on the primary format are rewritten.
@@ -461,7 +465,7 @@
 
   internal::Entry CreateEntry(Address address,
                               std::string_view key,
-                              span<const std::byte> value,
+                              std::span<const std::byte> value,
                               EntryState state);
 
   void LogSectors() const;
@@ -525,7 +529,7 @@
                       const Options& options = {})
       : KeyValueStoreBuffer(
             partition,
-            span(reinterpret_cast<const EntryFormat (&)[1]>(format)),
+            std::span(reinterpret_cast<const EntryFormat (&)[1]>(format)),
             options) {
     static_assert(kEntryFormats == 1,
                   "kEntryFormats EntryFormats must be specified");
@@ -534,7 +538,7 @@
   // Constructs a KeyValueStore on the partition. Supports multiple entry
   // formats. The first EntryFormat is used for new entries.
   KeyValueStoreBuffer(FlashPartition* partition,
-                      span<const EntryFormat, kEntryFormats> formats,
+                      std::span<const EntryFormat, kEntryFormats> formats,
                       const Options& options = {})
       : KeyValueStore(partition,
                       formats_,