Refactor codebase to support Minimum Supported Rust Version (MSRV) of 1.51.0 (#55)

pull/57/head
Chip Senkbeil 3 years ago committed by GitHub
parent f4eae0a467
commit 32639166bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ jobs:
- { rust: stable, os: ubuntu-latest } - { rust: stable, os: ubuntu-latest }
- { rust: stable, os: macos-latest } - { rust: stable, os: macos-latest }
- { rust: stable, os: windows-latest } - { rust: stable, os: windows-latest }
- { rust: 1.51.0, os: ubuntu-latest }
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install Rust ${{ matrix.rust }} - name: Install Rust ${{ matrix.rust }}
@ -44,6 +45,7 @@ jobs:
- { rust: stable, os: ubuntu-latest } - { rust: stable, os: ubuntu-latest }
- { rust: stable, os: macos-latest } - { rust: stable, os: macos-latest }
# - { rust: stable, os: windows-latest } # - { rust: stable, os: windows-latest }
- { rust: 1.51.0, os: ubuntu-latest }
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install Rust ${{ matrix.rust }} - name: Install Rust ${{ matrix.rust }}

@ -1,6 +1,6 @@
# distant # distant
[![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk] [![CI][distant_ci_img]][distant_ci_lnk] [![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk] [![CI][distant_rustc_img]][distant_rustc_lnk] [![CI][distant_ci_img]][distant_ci_lnk]
[distant_crates_img]: https://img.shields.io/crates/v/distant.svg [distant_crates_img]: https://img.shields.io/crates/v/distant.svg
[distant_crates_lnk]: https://crates.io/crates/distant [distant_crates_lnk]: https://crates.io/crates/distant
@ -8,6 +8,8 @@
[distant_doc_lnk]: https://docs.rs/distant [distant_doc_lnk]: https://docs.rs/distant
[distant_ci_img]: https://github.com/chipsenkbeil/distant/actions/workflows/ci.yml/badge.svg [distant_ci_img]: https://github.com/chipsenkbeil/distant/actions/workflows/ci.yml/badge.svg
[distant_ci_lnk]: https://github.com/chipsenkbeil/distant/actions/workflows/ci.yml [distant_ci_lnk]: https://github.com/chipsenkbeil/distant/actions/workflows/ci.yml
[distant_rustc_img]: https://img.shields.io/badge/distant-rustc_1.51+-lightgray.svg
[distant_rustc_lnk]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html
Binary to connect with a remote machine to edit files and run programs. Binary to connect with a remote machine to edit files and run programs.

@ -1,11 +1,13 @@
# distant core # distant core
[![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk] [![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk] [![Rustc 1.51.0][distant_rustc_img]][distant_rustc_lnk]
[distant_crates_img]: https://img.shields.io/crates/v/distant-core.svg [distant_crates_img]: https://img.shields.io/crates/v/distant-core.svg
[distant_crates_lnk]: https://crates.io/crates/distant-core [distant_crates_lnk]: https://crates.io/crates/distant-core
[distant_doc_img]: https://docs.rs/distant-core/badge.svg [distant_doc_img]: https://docs.rs/distant-core/badge.svg
[distant_doc_lnk]: https://docs.rs/distant-core [distant_doc_lnk]: https://docs.rs/distant-core
[distant_rustc_img]: https://img.shields.io/badge/distant_core-rustc_1.51+-lightgray.svg
[distant_rustc_lnk]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html
Library that powers the [`distant`](https://github.com/chipsenkbeil/distant) Library that powers the [`distant`](https://github.com/chipsenkbeil/distant)
binary. binary.

@ -277,14 +277,19 @@ impl FromStr for LspHeader {
let mut content_type = None; let mut content_type = None;
for line in lines { for line in lines {
if let Some((name, value)) = line.split_once(':') { match line.find(':') {
match name { Some(idx) if idx + 1 < line.len() => {
"Content-Length" => content_length = Some(value.trim().parse()?), let name = &line[..idx];
"Content-Type" => content_type = Some(value.trim().to_string()), let value = &line[(idx + 1)..];
_ => return Err(LspHeaderParseError::BadHeaderField), match name {
"Content-Length" => content_length = Some(value.trim().parse()?),
"Content-Type" => content_type = Some(value.trim().to_string()),
_ => return Err(LspHeaderParseError::BadHeaderField),
}
}
_ => {
return Err(LspHeaderParseError::BadHeaderField);
} }
} else {
return Err(LspHeaderParseError::BadHeaderField);
} }
} }

@ -589,12 +589,6 @@ pub enum ErrorKind {
/// reached prematurely /// reached prematurely
UnexpectedEof, UnexpectedEof,
/// This operation is unsupported on this platform
Unsupported,
/// An operation could not be completed, because it failed to allocate enough memory.
OutOfMemory,
/// When a loop is encountered when walking a directory /// When a loop is encountered when walking a directory
Loop, Loop,
@ -629,8 +623,6 @@ impl From<io::ErrorKind> for ErrorKind {
io::ErrorKind::Interrupted => Self::Interrupted, io::ErrorKind::Interrupted => Self::Interrupted,
io::ErrorKind::Other => Self::Other, io::ErrorKind::Other => Self::Other,
io::ErrorKind::UnexpectedEof => Self::UnexpectedEof, io::ErrorKind::UnexpectedEof => Self::UnexpectedEof,
io::ErrorKind::Unsupported => Self::Unsupported,
io::ErrorKind::OutOfMemory => Self::OutOfMemory,
// This exists because io::ErrorKind is non_exhaustive // This exists because io::ErrorKind is non_exhaustive
_ => Self::Unknown, _ => Self::Unknown,

@ -199,7 +199,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
transport.send(data).await.unwrap(); transport.send(data).await.unwrap();
@ -232,7 +232,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
tx.send(frame).await.unwrap(); tx.send(frame).await.unwrap();
@ -256,7 +256,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
tx.send(frame).await.unwrap(); tx.send(frame).await.unwrap();
@ -293,7 +293,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
tx.send(frame).await.unwrap(); tx.send(frame).await.unwrap();
@ -318,7 +318,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
tx.send(frame).await.unwrap(); tx.send(frame).await.unwrap();
@ -344,7 +344,7 @@ mod tests {
let bytes = serde_cbor::to_vec(&data).unwrap(); let bytes = serde_cbor::to_vec(&data).unwrap();
let len = (bytes.len() as u64).to_be_bytes(); let len = (bytes.len() as u64).to_be_bytes();
let mut frame = Vec::new(); let mut frame = Vec::new();
frame.extend(len); frame.extend(len.iter().copied());
frame.extend(bytes); frame.extend(bytes);
wh.send(data).await.unwrap(); wh.send(data).await.unwrap();

@ -64,12 +64,12 @@ impl FromStr for PortRange {
/// Parses PORT into single range or PORT1:PORTN into full range /// Parses PORT into single range or PORT1:PORTN into full range
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.split_once(':') { match s.find(':') {
Some((start, end)) => Ok(Self { Some(idx) if idx + 1 < s.len() => Ok(Self {
start: start.parse()?, start: s[..idx].parse()?,
end: Some(end.parse()?), end: Some(s[(idx + 1)..].parse()?),
}), }),
None => Ok(Self { _ => Ok(Self {
start: s.parse()?, start: s.parse()?,
end: None, end: None,
}), }),

@ -215,13 +215,16 @@ fn should_support_json_output_for_error(mut action_cmd: Command) {
assert!( assert!(
matches!( matches!(
res.payload[0], res.payload[0],
// NOTE: After some refactoring, unknown error type shows up in
// our CI but not on my local machine. I can't pin it down.
// The description matches what we'd expect regarding the
// directory not being empty, so for now going to support
// either of these error kinds.
ResponseData::Error(Error { ResponseData::Error(Error {
// NOTE: After some refactoring, unknown error type shows up in kind: ErrorKind::Other,
// our CI but not on my local machine. I can't pin it down. ..
// The description matches what we'd expect regarding the }) | ResponseData::Error(Error {
// directory not being empty, so for now going to support kind: ErrorKind::Unknown,
// either of these error kinds.
kind: ErrorKind::Other | ErrorKind::Unknown,
.. ..
}) })
), ),

Loading…
Cancel
Save