-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Cleaned up clippy lints - Removed `nonempty` dependency in favor of `helix-stdx-nonempty.rs` - Changed Register initialisation signature to take clipboard provider rather than configuration struct.
- Loading branch information
Showing
9 changed files
with
83 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod env; | ||
pub mod faccess; | ||
pub mod nonempty; | ||
pub mod path; | ||
pub mod rope; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use serde::{de::Error, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; | ||
|
||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash)] | ||
pub struct EmptyError; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct NonEmptyVec<T> | ||
where | ||
T: Clone, | ||
{ | ||
head: T, | ||
tail: Vec<T>, | ||
} | ||
|
||
impl<T: Clone> NonEmptyVec<T> { | ||
pub fn head(&self) -> &T { | ||
&self.head | ||
} | ||
|
||
pub fn tail(&self) -> &Vec<T> { | ||
&self.tail | ||
} | ||
|
||
pub fn from_vec(mut vec: Vec<T>) -> Option<Self> { | ||
if vec.is_empty() { | ||
None | ||
} else { | ||
let head = vec.remove(0); | ||
Some(Self { head, tail: vec }) | ||
} | ||
} | ||
} | ||
|
||
impl<T: Serialize + Clone> Serialize for NonEmptyVec<T> { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
let mut seq = serializer.serialize_seq(Some(self.tail.len() + 1))?; | ||
seq.serialize_element(&self.head)?; | ||
for e in &self.tail { | ||
seq.serialize_element(&e)?; | ||
} | ||
seq.end() | ||
} | ||
} | ||
|
||
impl<'de, T: Deserialize<'de> + Clone> Deserialize<'de> for NonEmptyVec<T> { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
let v = <Vec<T>>::deserialize(deserializer)?; | ||
let mut v = v.into_iter(); | ||
|
||
if let Some(first) = v.next() { | ||
Ok(NonEmptyVec { | ||
head: first, | ||
tail: v.collect(), | ||
}) | ||
} else { | ||
Err(D::Error::custom("vector must be non-empty")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters