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

Add the Serialize trait to Request::Params #140

Closed
maddyblue opened this issue Feb 26, 2020 · 1 comment · Fixed by #145
Closed

Add the Serialize trait to Request::Params #140

maddyblue opened this issue Feb 26, 2020 · 1 comment · Fixed by #145

Comments

@maddyblue
Copy link

(Caveat: I'm new to Rust so I may have an incorrect understanding of traits or something. Please correct me if so.)

I'm trying to use this crate to implement a lsp client for my editor. I'm trying to things in some good way and am attempting to write a method that I will serialize stuff for me. It looks like:

use lsp_types::request::Request;

pub fn marshal<R: Request>(params: R::Params) -> Result<Vec<u8>> {
	let mut s = Vec::new();
	let msg = serde_json::to_writer(&mut s, &params)?;
	Ok(s)
}

The serde_json call complains because params doesn't implement the serde::ser::Serialize trait. I think this is true because it's not listed in the Request trait. However, all of the Params actually do implement that trait, so I think it can safely be added to the Request trait. Is this the case?

@Marwes
Copy link
Member

Marwes commented Feb 28, 2020

I think this is ok, just being conservative/forgot about it. There was an equivalent issue for Deserialize #70 so it ought to be Serialize + DeserializeOwned

Marwes added a commit that referenced this issue Feb 29, 2020
This will always be true since otherwise there would be no way to
send/receive the params or result.

Fixes #140
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 a pull request may close this issue.

2 participants