orphanage

Check-in Differences
Login

Check-in Differences

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

Difference From orphanage-0.0.3 To orphanage-0.0.4

2024-10-07
01:13
Implement Clone and Deref for ExpandedPath. check-in: 99fe9a59fa user: jan tags: trunk
2024-10-06
22:12
Add ExpandedPath. check-in: b3c52dc5fc user: jan tags: orphanage-0.0.4, trunk
2024-09-20
12:47
Add an example/test for if_some. check-in: d5a667fbd8 user: jan tags: trunk
2024-09-14
04:25
Release maintenance. check-in: fc63db4c72 user: jan tags: orphanage-0.0.3, trunk
04:20
Dependency maintenance. check-in: 378b233fa9 user: jan tags: trunk

Changes to .efiles.

10
11
12
13
14
15
16


src/buf.rs
src/sqlfuncs.rs
src/futures.rs
src/iox.rs
src/tokiox.rs
src/tokiox/tcpconn.rs
src/serde_parsers.rs









>
>
10
11
12
13
14
15
16
17
18
src/buf.rs
src/sqlfuncs.rs
src/futures.rs
src/iox.rs
src/tokiox.rs
src/tokiox/tcpconn.rs
src/serde_parsers.rs
examples/fut_if_some.rs
examples/deser.rs

Changes to Cargo.toml.

1
2
3
4
5
6
7
8
9
10
[package]
name = "orphanage"
version = "0.0.3"
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.0.4"
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."
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
tokio = ["dep:tokio", "dep:async-trait", "dep:killswitch"]
rusqlite = ["dep:rusqlite", "dep:sha2"]
serde = ["dep:serde", "dep:parse-size"]

[dependencies]
async-trait = { version = "0.1.82", optional = true }
killswitch = { version = "0.4.2", optional = true }
parse-size = { version = "1.0.0", optional = true }
rand = { version = "0.8.5" }
rusqlite = { version = "0.32.1", optional = true, features = ["functions"] }
serde = { version = "1.0.210", optional = true, features = ["derive"] }
sha2 = { version = "0.10.7", optional = true }
shellexpand = { version = "3.1.0" }
tokio = { version = "1.40.0", optional = true, features = [
  "macros", "net", "time"
] }







[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }

multiple_crate_versions = "allow"








|









>
>
>
>
>
>












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
tokio = ["dep:tokio", "dep:async-trait", "dep:killswitch"]
rusqlite = ["dep:rusqlite", "dep:sha2"]
serde = ["dep:serde", "dep:parse-size"]

[dependencies]
async-trait = { version = "0.1.82", optional = true }
killswitch = { version = "0.4.2", optional = true }
parse-size = { version = "1.1.0", optional = true }
rand = { version = "0.8.5" }
rusqlite = { version = "0.32.1", optional = true, features = ["functions"] }
serde = { version = "1.0.210", optional = true, features = ["derive"] }
sha2 = { version = "0.10.7", optional = true }
shellexpand = { version = "3.1.0" }
tokio = { version = "1.40.0", optional = true, features = [
  "macros", "net", "time"
] }

[dev-dependencies]
killswitch = { version = "0.4.2" }
tokio = { version = "1.40.0", features = ["full"] }
tokio-test = { version = "0.4.3" }
toml = { version = "0.8.18" }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }

multiple_crate_versions = "allow"

Added examples/deser.rs.





















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
#[cfg(feature = "serde")]
mod inner {
  use serde::Deserialize;

  use orphanage::serde_parsers::ExpandedPath;

  #[derive(Debug, Deserialize)]
  #[allow(dead_code)]
  struct Config {
    #[serde(rename = "expanded-path")]
    epth: ExpandedPath,

    #[serde(default, rename = "optional-expanded-path")]
    optepth: Option<ExpandedPath>
  }

  #[cfg(feature = "serde")]
  pub fn main() {
    match toml::from_str::<Config>(
      r#"
expanded-path = "~/tmp"
"#
    ) {
      Ok(config) => {
        println!("{config:?}");
      }
      Err(e) => {
        println!("{e}");
      }
    }

    match toml::from_str::<Config>(
      r#"
optional-expanded-path = "$NonExistent"
"#
    ) {
      Ok(config) => {
        println!("{config:?}");
      }
      Err(e) => {
        println!("{e}");
      }
    }
  }
}


#[cfg(feature = "serde")]
fn main() {
  inner::main();
}

#[cfg(not(feature = "serde"))]
fn main() {
  println!("Example requires `serde` feature");
}

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

Added examples/fut_if_some.rs.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
34
35
36
37
38
39
40
use std::time::Duration;

use orphanage::futures::if_some;

use tokio::{task, time::sleep};

use killswitch::KillSwitch;

#[tokio::main(flavor = "multi_thread")]
async fn main() {
  let ks = KillSwitch::new();

  let ks2 = ks.clone();
  task::spawn(async move {
    sleep(Duration::from_secs(1)).await;
    ks2.trigger();
  });

  println!("Should sleep for 1 second, and is then killed");
  maybe_kill_sleep(Some(&ks)).await;

  println!("Should sleep for 4 seconds, and then expires");
  maybe_kill_sleep(None).await;
}


#[allow(clippy::redundant_pub_crate)]
async fn maybe_kill_sleep(ks: Option<&KillSwitch>) {
  let mut kwfut = ks.map(KillSwitch::wait);
  tokio::select! {
    _ = if_some(&mut kwfut) => {
      println!("Killed");
    }
    () = sleep(Duration::from_secs(4)) => {
      println!("Expired");
    }
  }
}

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

Changes to src/serde_parsers.rs.

17
18
19
20
21
22
23
24



25
26


27
28
29
30
31
32
33
//!   /// Support optional `binsize = 65536` and `binsize = "64KB"`
//!   binsize_opt: Option<BinSize>,
//!
//!   /// Support `decsize = 20000` and `decsize = "20KB"`
//!   decsize: DecSize,
//!
//!   /// Support optional `decsize = 20000` and `decsize = "20KB"`
//!   decsize_opt: Option<DecSize>



//! }
//! ```



use serde::{de::Deserializer, Deserialize};

#[derive(Debug, Default, PartialEq, Eq)]
pub struct Count(pub u64);

impl Count {







|
>
>
>


>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//!   /// Support optional `binsize = 65536` and `binsize = "64KB"`
//!   binsize_opt: Option<BinSize>,
//!
//!   /// Support `decsize = 20000` and `decsize = "20KB"`
//!   decsize: DecSize,
//!
//!   /// Support optional `decsize = 20000` and `decsize = "20KB"`
//!   decsize_opt: Option<DecSize>,
//!
//!   /// Support optional `~/tmp`
//!   epth: Option<ExpandedPath>
//! }
//! ```

use std::path::{Path, PathBuf};

use serde::{de::Deserializer, Deserialize};

#[derive(Debug, Default, PartialEq, Eq)]
pub struct Count(pub u64);

impl Count {
141
142
143
144
145
146
147




































148
  where
    D: Deserializer<'de>
  {
    decsize(deserializer)
  }
}





































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







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

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  where
    D: Deserializer<'de>
  {
    decsize(deserializer)
  }
}


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

impl ExpandedPath {
  #[must_use]
  pub fn get(&self) -> &Path {
    &self.0
  }
}


#[allow(clippy::missing_errors_doc)]
pub fn expand_path<'de, D>(deserializer: D) -> Result<ExpandedPath, D::Error>
where
  D: Deserializer<'de>
{
  let s = String::deserialize(deserializer)?;
  match shellexpand::full(&s) {
    Ok(value) => Ok(ExpandedPath(PathBuf::from(value.into_owned()))),
    Err(e) => {
      let msg = format!("Unable to expand path; {e}");
      Err(serde::de::Error::custom(msg))
    }
  }
}

impl<'de> Deserialize<'de> for ExpandedPath {
  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  where
    D: Deserializer<'de>
  {
    expand_path(deserializer)
  }
}

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

Changes to www/changelog.md.

1
2
3
4
5
6
7


8
9
10
11
12
13
14
# Change Log

## [Unreleased]

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

### Added



### Changed

### Removed

---








>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Change Log

## [Unreleased]

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

### Added

Add a `ExpandedPath` deserializer.

### Changed

### Removed

---