Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DetachedSlice with different content? #25

Open
aminya opened this issue Dec 29, 2023 · 0 comments
Open

DetachedSlice with different content? #25

aminya opened this issue Dec 29, 2023 · 0 comments

Comments

@aminya
Copy link
Contributor

aminya commented Dec 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant