Skip to content

Commit

Permalink
[External] [stdlib] Make StringSlice CollectionElement (#49050)
Browse files Browse the repository at this point in the history
[External] [stdlib] Make `StringSlice` `CollectionElement`

Make `StringSlice` `CollectionElement`

ORIGINAL_AUTHOR=martinvuyk
<[email protected]>
PUBLIC_PR_LINK=#3597

Co-authored-by: martinvuyk <[email protected]>
Closes #3597
MODULAR_ORIG_COMMIT_REV_ID: 4a6d29b9abbe111bd0c5dbf001e69d75729c6750
  • Loading branch information
modularbot and martinvuyk committed Oct 16, 2024
1 parent c0f150f commit c6f3b20
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions stdlib/src/utils/string_slice.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ struct _StringSliceIter[
return self.index - self.continuation_bytes


@value
struct StringSlice[
is_mutable: Bool, //,
origin: Origin[is_mutable].type,
](Stringable, Sized, Formattable):
"""
A non-owning view to encoded string data.
](Stringable, Sized, Formattable, CollectionElement, CollectionElementNew):
"""A non-owning view to encoded string data.
TODO:
The underlying string data is guaranteed to be encoded using UTF-8.
Expand Down Expand Up @@ -307,6 +307,15 @@ struct StringSlice[

self._slice = byte_slice

@always_inline
fn __init__(inout self, *, other: Self):
"""Explicitly construct a deep copy of the provided `StringSlice`.
Args:
other: The `StringSlice` to copy.
"""
self._slice = other._slice

# ===------------------------------------------------------------------===#
# Trait implementations
# ===------------------------------------------------------------------===#
Expand Down

0 comments on commit c6f3b20

Please sign in to comment.