Skip to content

DetachedSlice with different content?  #25

@aminya

Description

@aminya

I have a use case where I want to manually create a slice into a source string by setting the final string content and the original offset. When I want to refer to the content I would just ignore the original_offset.

Here is the implementation I have come up with:

pub struct DetachedImString<S: Data<String>> {
    content: S,
    original_offset: Range<usize>,
}

impl DetachedImString {
    pub fn as_str(&self) -> &str {
       return &self.content
    }
}

pub enum MaybeDetachedImString {
  Attached(ImString),
  Detached(DetachedImString)
}

I wonder if this use case is something useful for others so that I submit a PR, and if you have any notes on the approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions