orphanage

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From orphanage-0.2.1 To orphanage-0.2.2

2025-04-15
00:31
Release maintenance. Leaf check-in: 8c4b44de1e user: jan tags: orphanage-0.2.2, trunk
00:30
Changelog updates. check-in: de48492192 user: jan tags: trunk
2025-04-13
19:43
Add buf::random_size() for genrating a random buffer of random size. check-in: d01d6e0899 user: jan tags: trunk
2025-04-03
00:55
Release maintenance. check-in: 4d85544ea5 user: jan tags: orphanage-0.2.1, trunk
00:53
Change log fixups. check-in: 0ab734aab1 user: jan tags: trunk

Changes to .efiles.

16
17
18
19
20
21
22

src/setops.rs
src/ffi.rs
tests/setops.rs
examples/fut_if_some.rs
examples/deser.rs
examples/slasher.rs
examples/diskfree.rs








>
16
17
18
19
20
21
22
23
src/setops.rs
src/ffi.rs
tests/setops.rs
examples/fut_if_some.rs
examples/deser.rs
examples/slasher.rs
examples/diskfree.rs
examples/rndbuf.rs

Changes to Cargo.toml.

1
2
3
4
5
6
7
8
9
10
[package]
name = "orphanage"
version = "0.2.1"
edition = "2021"
license = "0BSD"
# https://crates.io/category_slugs
categories = [ "network-programming" ]
keywords = [ "sqlite", "fs", "path" ]
repository = "https://repos.qrnch.tech/pub/orphanage"
description = "Random collection of stuff that is still searching for a home."


|







1
2
3
4
5
6
7
8
9
10
[package]
name = "orphanage"
version = "0.2.2"
edition = "2021"
license = "0BSD"
# https://crates.io/category_slugs
categories = [ "network-programming" ]
keywords = [ "sqlite", "fs", "path" ]
repository = "https://repos.qrnch.tech/pub/orphanage"
description = "Random collection of stuff that is still searching for a home."

Added examples/rndbuf.rs.

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
use orphanage::buf::random_size;

fn main() {
  let buf = random_size(1..=16);
  println!("len={}", buf.len());
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to src/buf.rs.



1
2
3
4
5
6
7
8


use rand::Rng;

// Note: We're shutting up clippy here because it says that we should be using
// MaybeUninit, which it is correct about.  However, the rand crate maintainers
// think that filling MaybeUninit is bad and that application should be forced
// to double-initialize buffers, which is obviously wrong.  But it's their
// crate, so we're doing it this way instead.
#[allow(clippy::uninit_vec)]
>
>
|







1
2
3
4
5
6
7
8
9
10
use std::fmt;

use rand::{distr::uniform::SampleRange, Rng};

// Note: We're shutting up clippy here because it says that we should be using
// MaybeUninit, which it is correct about.  However, the rand crate maintainers
// think that filling MaybeUninit is bad and that application should be forced
// to double-initialize buffers, which is obviously wrong.  But it's their
// crate, so we're doing it this way instead.
#[allow(clippy::uninit_vec)]
16
17
18
19
20
21
22
















































































23
  }

  rand::rng().fill(&mut buf[..]);

  buf
}

















































































// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  }

  rand::rng().fill(&mut buf[..]);

  buf
}


pub fn random_size<R>(range: R) -> Vec<u8>
where
  R: SampleRange<usize>
{
  let sz = rand::rng().random_range::<usize, R>(range);
  random(sz)
}


/// Hex dump byte-by-byte, but rle code repeated
pub struct ByteReps<'a>(pub &'a [u8]);

struct RepeatedByte {
  byte: u8,
  count: usize
}

impl fmt::Debug for RepeatedByte {
  fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result {
    match self.count {
      1 => write!(fmtr, "0x{:02x}", self.byte),
      _ => write!(fmtr, "0x{:02x}*{}", self.byte, self.count)
    }
  }
}

impl fmt::Debug for ByteReps<'_> {
  fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result {
    let mut list = fmtr.debug_list();
    let [mut byte, rest @ ..] = self.0 else {
      return list.finish();
    };
    let mut count: usize = 1;
    for &this in rest {
      if byte == this {
        count += 1;
        continue;
      }

      list.entry(&RepeatedByte { byte, count });
      count = 1;
      byte = this;
    }

    list.entry(&RepeatedByte { byte, count });
    list.finish()
  }
}

impl fmt::Display for ByteReps<'_> {
  fn fmt(&self, fmtr: &mut fmt::Formatter<'_>) -> fmt::Result {
    <Self as fmt::Debug>::fmt(self, fmtr)
  }
}


#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn hex_rle() {
    let buf = [0];
    assert_eq!(ByteReps(&buf).to_string(), "[0x00]");

    let buf = [0, 0];
    assert_eq!(ByteReps(&buf).to_string(), "[0x00*2]");

    let buf = [0, 1];
    assert_eq!(ByteReps(&buf).to_string(), "[0x00, 0x01]");

    let buf = [0, 0, 1, 1];
    assert_eq!(ByteReps(&buf).to_string(), "[0x00*2, 0x01*2]");

    let buf = [0, 0, 1, 1, 0, 0];
    assert_eq!(ByteReps(&buf).to_string(), "[0x00*2, 0x01*2, 0x00*2]");
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to src/numx.rs.



1
2
3
4
5
6
7


use paste::paste;

pub trait UnsignedExt {
  type Type;

  /// Round down integer to its closes power-of-two.
  fn round_down_to_pow2(self) -> Self::Type;
>
>







1
2
3
4
5
6
7
8
9
use std::fmt::Write;

use paste::paste;

pub trait UnsignedExt {
  type Type;

  /// Round down integer to its closes power-of-two.
  fn round_down_to_pow2(self) -> Self::Type;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

  let mut it = blocks.iter().peekable();

  while let Some((start, end)) = it.next() {
    if start == end {
      res.push_str(&start.to_string());
    } else {
      res.push_str(&format!("{start}-{end}"));
    }

    if it.peek().is_some() {
      res.push(',');
    }
  }








|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

  let mut it = blocks.iter().peekable();

  while let Some((start, end)) = it.next() {
    if start == end {
      res.push_str(&start.to_string());
    } else {
      let _ = write!(res, "{start}-{end}");
    }

    if it.peek().is_some() {
      res.push(',');
    }
  }

Changes to src/serde_parsers.rs.

155
156
157
158
159
160
161



162
163
164
165
166
167
168


#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ExpandedPath(pub PathBuf);

impl ExpandedPath {
  #[must_use]



  pub fn get(&self) -> &Path {
    &self.0
  }

  #[must_use]
  pub fn into_inner(self) -> PathBuf {
    self.0







>
>
>







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171


#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ExpandedPath(pub PathBuf);

impl ExpandedPath {
  #[must_use]
  // ToDo: broken-lint
  // Suggests const, but const breaks compilation
  #[allow(clippy::missing_const_for_fn)]
  pub fn get(&self) -> &Path {
    &self.0
  }

  #[must_use]
  pub fn into_inner(self) -> PathBuf {
    self.0

Changes to www/changelog.md.

1
2
3
4
5
6
7
8
9
10
11
12
13
14












15
16
17
18
19
20
21
# Change Log

⚠️  indicates a breaking change.

## [Unreleased]

[Details](/vdiff?from=orphanage-0.2.1&to=trunk)

### Added

### Changed

### Removed













---

## [0.2.1] - 2025-04-03

[Details](/vdiff?from=orphanage-0.2.0&to=orphanage-0.2.1)

### Changed






|







>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Change Log

⚠️  indicates a breaking change.

## [Unreleased]

[Details](/vdiff?from=orphanage-0.2.2&to=trunk)

### Added

### Changed

### Removed

---

## [0.2.2] - 2025-04-15

[Details](/vdiff?from=orphanage-0.2.1&to=orphanage-0.2.2)

### Added

- Add `buf::random_size()` to allow generating a random buffer of random
  size.
- Add `buf::ByteReps` for writing RLE-coded hex dumps.

---

## [0.2.1] - 2025-04-03

[Details](/vdiff?from=orphanage-0.2.0&to=orphanage-0.2.1)

### Changed