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

impl TextLen for &'_ Arc<String> #45

Open
Matthias-Fauconneau opened this issue May 1, 2020 · 5 comments
Open

impl TextLen for &'_ Arc<String> #45

Matthias-Fauconneau opened this issue May 1, 2020 · 5 comments

Comments

@Matthias-Fauconneau
Copy link

Matthias-Fauconneau commented May 1, 2020

Is this intentionally missing ?
Would be nice :)

impl TextLen for &'_ Arc<String> {
    fn text_len(self) -> TextSize {
        use std::ops::Deref;
        self.deref().text_len()
    }
}

TextSize::of:

Types that don't dereference to str but want to be usable in this constructor can implement TextLen.

But the trait is Sealed without a rationale :(

@matklad
Copy link
Member

matklad commented May 1, 2020

Kind of: we just follow the concervative set of impls of std::Pattern: https://doc.rust-lang.org/stable/std/str/pattern/trait.Pattern.html#implementors

@Matthias-Fauconneau
Copy link
Author

Maybe that's a restriction which makes more sense for std though.
But more importantly, this cannot be worked around because of the Sealed :(

@matklad
Copy link
Member

matklad commented May 1, 2020

Yes, this needs to be fixed at the call-site by calling .as_str(), which doesn't seem like the end of the world to me :)

@CAD97
Copy link
Collaborator

CAD97 commented May 1, 2020

That's definitely out-of-date documentation on TextSize::of; I wrote it when we had much more aggressive blanket impls for TextLen.

Our general consensus (for 1.0 at least) was that TextSize::of should be used just for primitives (i.e. what was of_str and of_char in text_unit), and compound types could either provide a primitive conversion (to feed into TextSize::of), or its own ad-hoc accessor.

@CAD97
Copy link
Collaborator

CAD97 commented May 1, 2020

we just follow the concervative set of impls of std::Pattern

We should probably add an impl for &[char] then...

bors bot added a commit that referenced this issue May 1, 2020
46: Fix TextSize::of docs to no longer suggest implementing TextLen r=matklad a=CAD97

Addresses the misleading docs part of #45 by editing the docs back to their minimum. Does not yet provide advice on idioms for non-primitive types.

Co-authored-by: CAD97 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants