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

Implement Candidate for str #447

Merged
merged 1 commit into from
Oct 4, 2020
Merged

Implement Candidate for str #447

merged 1 commit into from
Oct 4, 2020

Conversation

gwenn
Copy link
Collaborator

@gwenn gwenn commented Oct 4, 2020

Should fix #443

@gwenn gwenn merged commit 928ad1f into kkawakam:master Oct 4, 2020
@gwenn gwenn deleted the candidate_str branch October 4, 2020 06:52
@LoganDark
Copy link

How exactly am I expected to provide a vector of str? They're literally DSTs.

@gwenn
Copy link
Collaborator Author

gwenn commented Apr 7, 2021

How exactly am I expected to provide a vector of str? They're literally DSTs.

Please provide a minimal example that should but doesn't work.

@LoganDark
Copy link

How exactly am I expected to provide a vector of str? They're literally DSTs.

Please provide a minimal example that should but doesn't work.

impl Completer for LineHelper {
	type Candidate = &'static str;

	fn complete(
		&self,
		_line: &str,
		_pos: usize,
		_ctx: &rustyline::Context<'_>,
	) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
		Ok((0, vec!["test1", "test2"]))
	}
}

@gwenn
Copy link
Collaborator Author

gwenn commented Apr 7, 2021

How exactly am I expected to provide a vector of str? They're literally DSTs.

Please provide a minimal example that should but doesn't work.

impl Completer for LineHelper {
	type Candidate = &'static str;

	fn complete(
		&self,
		_line: &str,
		_pos: usize,
		_ctx: &rustyline::Context<'_>,
	) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
		Ok((0, vec!["test1", "test2"]))
	}
}

Candidate should be str: type Candidate = str;

@LoganDark
Copy link

LoganDark commented Apr 7, 2021

How exactly am I expected to provide a vector of str? They're literally DSTs.

Please provide a minimal example that should but doesn't work.

impl Completer for LineHelper {
	type Candidate = &'static str;

	fn complete(
		&self,
		_line: &str,
		_pos: usize,
		_ctx: &rustyline::Context<'_>,
	) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
		Ok((0, vec!["test1", "test2"]))
	}
}

Candidate should be str: type Candidate = str;

Exactly, and then I can't return a Vec<Self::Candidate> because str is a DST. Try it yourself.

The issue is that str is unusable as a candidate because it is not Sized. But I can't use &str as the candidate because you only implement Candidate for str itself.

@gwenn
Copy link
Collaborator Author

gwenn commented Apr 7, 2021

How exactly am I expected to provide a vector of str? They're literally DSTs.

Please provide a minimal example that should but doesn't work.

impl Completer for LineHelper {
	type Candidate = &'static str;

	fn complete(
		&self,
		_line: &str,
		_pos: usize,
		_ctx: &rustyline::Context<'_>,
	) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
		Ok((0, vec!["test1", "test2"]))
	}
}

Candidate should be str: type Candidate = str;

Exactly, and then I can't return a Vec<Self::Candidate> because str is a DST. Try it yourself.

The issue is that str is unusable as a candidate because it is not Sized. But I can't use &str as the candidate because you only implement Candidate for str itself.

You are right.
And I don't remember why I provided an impl for str and not:

impl Candidate for &'static str {
    fn display(&self) -> &str {
        self
    }

    fn replacement(&self) -> &str {
        self
    }
}

@LoganDark
Copy link

LoganDark commented Apr 7, 2021

You are right.
And I don't remember why I provided an impl for str and not:

impl Candidate for &'static str {
    fn display(&self) -> &str {
        self
    }

    fn replacement(&self) -> &str {
        self
    }
}

I believe it was because you (or someone) raised concerns about only supporting 'static and not other lifetimes. But changing that would mean rustyline v9.0.0, so...

@gwenn
Copy link
Collaborator Author

gwenn commented Apr 7, 2021

I believe it was because you (or someone) raised concerns about only supporting 'static and not other lifetimes. But changing that would mean rustyline v9.0.0, so...

No, we can still patch v8 and provide an impl for &'static str (and keep the old / unusable one).
See #512

@LoganDark
Copy link

I believe it was because you (or someone) raised concerns about only supporting 'static and not other lifetimes. But changing that would mean rustyline v9.0.0, so...

No, we can still patch v8 and provide an impl for &'static str (and keep the old / unusable one).
See #512

I meant supporting other lifetimes would mean v9, so yeah, supporting static can be done here.

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

Successfully merging this pull request may close these issues.

Implement Candidate for &str
2 participants