imstr icon indicating copy to clipboard operation
imstr copied to clipboard

`DetachedSlice` with different content?

Open aminya opened this issue 2 years ago • 0 comments

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.

aminya avatar Dec 29 '23 12:12 aminya