Skip to content

Commit

Permalink
new: fields and message expansion feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Jun 5, 2024
1 parent 2163576 commit 573a429
Show file tree
Hide file tree
Showing 36 changed files with 1,085 additions and 155 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <[email protected]>"]
version = "0.29.7-alpha.1"
version = "0.30.0-alpha.1"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -53,11 +53,13 @@ encstr = { path = "./crate/encstr" }
enum-map = "2"
flate2 = "1"
heapless = "0"
heapopt = { path = "./crate/heapopt" }
hex = "0"
htp = { git = "https://github.com/pamburus/htp.git" }
humantime = "2"
itertools = "0.13"
itoa = { version = "1", default-features = false }
mline = { path = "./crate/mline" }
notify = { version = "6", features = ["macos_kqueue"] }
nu-ansi-term = "0"
num_cpus = "1"
Expand Down
2 changes: 2 additions & 0 deletions crate/encstr/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ impl fmt::Display for Error {
}
}
}

impl std::error::Error for Error {}
1 change: 1 addition & 0 deletions crate/heapopt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
12 changes: 12 additions & 0 deletions crate/heapopt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
description = "Optimized collections for minimal heap usage"
name = "heapopt"
version = "0.1.0"
workspace = "../.."
repository.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
heapless = "0"
113 changes: 113 additions & 0 deletions crate/heapopt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#[derive(Default)]
pub struct Vec<T, const N: usize> {
head: heapless::Vec<T, N>,
tail: std::vec::Vec<T>,
}

impl<T, const N: usize> Vec<T, N> {
#[inline]
pub fn new() -> Self {
Self {
head: heapless::Vec::new(),
tail: std::vec::Vec::new(),
}
}

#[inline]
pub fn iter(&self) -> std::iter::Chain<std::slice::Iter<T>, std::slice::Iter<T>> {
self.head.iter().chain(self.tail.iter())
}

#[inline]
pub fn push(&mut self, value: T) {
if let Err(value) = self.head.push(value) {
self.tail.push(value);
}
}

#[inline]
pub fn pop(&mut self) -> Option<T> {
if let Some(value) = self.tail.pop() {
return Some(value);
}
self.head.pop()
}

#[inline]
pub fn len(&self) -> usize {
self.head.len() + self.tail.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.head.is_empty() && self.tail.is_empty()
}

#[inline]
pub fn resize(&mut self, new_len: usize, value: T)
where
T: Clone,
{
if new_len <= self.head.len() {
self.head.truncate(new_len);
self.tail.clear();
} else if new_len <= self.len() {
self.tail.resize(new_len - self.head.len(), value);
}
}

#[inline]
pub fn clear(&mut self) {
self.head.clear();
self.tail.clear();
}
}

impl<T, const N: usize> std::ops::Deref for Vec<T, N> {
type Target = [T];

#[inline]
fn deref(&self) -> &Self::Target {
self.head.as_slice()
}
}

impl<T, const N: usize> std::ops::DerefMut for Vec<T, N> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.head.as_mut_slice()
}
}

impl<T, const N: usize> std::ops::Index<usize> for Vec<T, N> {
type Output = T;

#[inline]
fn index(&self, index: usize) -> &Self::Output {
if index < self.head.len() {
&self.head[index]
} else {
&self.tail[index - self.head.len()]
}
}
}

impl<T, const N: usize> std::ops::IndexMut<usize> for Vec<T, N> {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
if index < self.head.len() {
&mut self.head[index]
} else {
&mut self.tail[index - self.head.len()]
}
}
}

impl<T, const N: usize> std::fmt::Debug for Vec<T, N>
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}
1 change: 1 addition & 0 deletions crate/mline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
13 changes: 13 additions & 0 deletions crate/mline/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
description = "Multi-line string manipulation library for Rust"
name = "mline"
version = "0.1.0"
workspace = "../.."
repository.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
heapopt = { path = "../heapopt" }
itertools = "0.13"
Loading

0 comments on commit 573a429

Please sign in to comment.