Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: radicle-core: Make this crate `no_std`
Lorenz Leutgeb committed 3 months ago
commit 5c859bb84f60f1c7a8c31315787b0eb46f18f92a
parent 27cc82060e4e4c6c54d5bf5aa7b645cf049e763f
16 files changed +66 -30
modified Cargo.toml
@@ -66,7 +66,7 @@ signature = "2.2"
snapbox = "0.4.3"
sqlite = "0.32.0"
tempfile = "3.3.0"
-
thiserror = "2"
+
thiserror = { version = "2", default-features = false }
winpipe = "0.1.1"
zeroize = "1.5.7"

modified crates/radicle-cli-test/Cargo.toml
@@ -18,4 +18,4 @@ pretty_assertions = { workspace = true }
radicle = { workspace = true, features = ["logger", "test"]}
shlex = { workspace = true }
snapbox = { workspace = true }
-
thiserror = { workspace = true }

\ No newline at end of file
+
thiserror = { workspace = true, default-features = true }

\ No newline at end of file
modified crates/radicle-cli/Cargo.toml
@@ -35,7 +35,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
shlex = { workspace = true }
tempfile = { workspace = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }
timeago = { version = "0.4.2", default-features = false }
tree-sitter = "0.24.4"
tree-sitter-bash = "0.23.3"
modified crates/radicle-cob/Cargo.toml
@@ -32,7 +32,7 @@ radicle-oid = { workspace = true, features = ["git2", "serde", "std"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
signature = { workspace = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }

[dev-dependencies]
fastrand = { workspace = true }
modified crates/radicle-core/Cargo.toml
@@ -11,8 +11,10 @@ rust-version.workspace = true

# For documentation of features refer to the module documentation in `./lib.rs`
[features]
+
default = ["std"]
git2 = ["dep:git2", "radicle-oid/git2"]
gix = ["dep:gix-hash", "radicle-oid/gix"]
+
std = ["radicle-oid/std", "thiserror/std", "schemars/std", "serde/std"]

[dependencies]
git2 = { workspace = true, optional = true }
@@ -21,11 +23,11 @@ multibase = { workspace = true }
proptest = { workspace = true, optional = true }
qcheck = { workspace = true, optional = true }
radicle-git-ref-format = { workspace = true, optional = true }
-
radicle-oid = { workspace = true, features = ["sha1", "std"] }
+
radicle-oid = { workspace = true, default-features = false, features = ["sha1"] }
schemars = { workspace = true, optional = true, default-features = false, features = ["derive"] }
serde = { workspace = true, optional = true, default-features = false }
sqlite = { workspace = true, optional = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = false }

[dev-dependencies]
proptest = { workspace = true }
modified crates/radicle-core/src/lib.rs
@@ -1,8 +1,16 @@
+
#![no_std]
+

//! This a crate for defining core data type for the Radicle protocol, such as
//! [`RepoId`].
//!
//! # Feature Flags
//!
+
//! ## `std`
+
//!
+
//! [`OsString`]: ::doc_std::ffi::OsString
+
//!
+
//! Provides implementation of [`TryFrom<OsString>`].
+
//!
//! ## `git2`
//!
//! [`git2::Oid`]: ::git2::Oid
@@ -56,5 +64,7 @@
#[cfg(doc)]
extern crate std as doc_std;

+
extern crate alloc;
+

pub mod repo;
pub use repo::RepoId;
modified crates/radicle-core/src/repo.rs
@@ -1,5 +1,6 @@
-
use std::ops::Deref;
-
use std::{ffi::OsString, fmt, str::FromStr};
+
use alloc::string::String;
+
use alloc::string::ToString as _;
+
use alloc::vec::Vec;

use radicle_oid::Oid;
use thiserror::Error;
@@ -16,7 +17,7 @@ pub enum IdError {
}

/// A repository identifier.
-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct RepoId(
    #[cfg_attr(feature = "schemars", schemars(
@@ -29,14 +30,14 @@ pub struct RepoId(
    Oid,
);

-
impl fmt::Display for RepoId {
-
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+
impl core::fmt::Display for RepoId {
+
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_str(self.urn().as_str())
    }
}

-
impl fmt::Debug for RepoId {
-
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+
impl core::fmt::Debug for RepoId {
+
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "RepoId({self})")
    }
}
@@ -47,7 +48,7 @@ impl RepoId {
    /// Eg. `rad:z3XncAdkZjeK9mQS5Sdc4qhw98BUX`.
    ///
    pub fn urn(&self) -> String {
-
        format!("{RAD_PREFIX}{}", self.canonical())
+
        RAD_PREFIX.to_string() + &self.canonical()
    }

    /// Parse an identifier from the human-readable URN format.
@@ -80,7 +81,7 @@ impl RepoId {
    }
}

-
impl FromStr for RepoId {
+
impl core::str::FromStr for RepoId {
    type Err = IdError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -88,12 +89,27 @@ impl FromStr for RepoId {
    }
}

-
impl TryFrom<OsString> for RepoId {
-
    type Error = IdError;
+
#[cfg(feature = "std")]
+
mod std_impls {
+
    extern crate std;

-
    fn try_from(value: OsString) -> Result<Self, Self::Error> {
-
        let string = value.to_string_lossy();
-
        Self::from_canonical(&string)
+
    use super::{IdError, RepoId};
+

+
    use std::ffi::OsString;
+

+
    impl TryFrom<OsString> for RepoId {
+
        type Error = IdError;
+

+
        fn try_from(value: OsString) -> Result<Self, Self::Error> {
+
            let string = value.to_string_lossy();
+
            Self::from_canonical(&string)
+
        }
+
    }
+

+
    impl std::hash::Hash for RepoId {
+
        fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+
            self.0.hash(state)
+
        }
    }
}

@@ -103,7 +119,7 @@ impl From<Oid> for RepoId {
    }
}

-
impl Deref for RepoId {
+
impl core::ops::Deref for RepoId {
    type Target = Oid;

    fn deref(&self) -> &Self::Target {
@@ -135,6 +151,8 @@ mod gix_impls {

#[cfg(feature = "radicle-git-ref-format")]
mod radicle_git_ref_format_impls {
+
    use alloc::string::ToString;
+

    use radicle_git_ref_format::{Component, RefString};

    use super::RepoId;
@@ -150,6 +168,8 @@ mod radicle_git_ref_format_impls {

#[cfg(feature = "serde")]
mod serde_impls {
+
    use alloc::string::String;
+

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

    use super::RepoId;
@@ -198,6 +218,9 @@ mod serde_impls {

#[cfg(feature = "sqlite")]
mod sqlite_impls {
+
    use alloc::format;
+
    use alloc::string::ToString;
+

    use super::RepoId;

    use sqlite::{BindableWithIndex, Error, ParameterIndex, Statement, Value};
@@ -255,6 +278,7 @@ mod test {
    use proptest::proptest;

    fn prop_roundtrip_parse(rid: RepoId) {
+
        use core::str::FromStr as _;
        let encoded = rid.to_string();
        let decoded = RepoId::from_str(&encoded).unwrap();

modified crates/radicle-crypto/Cargo.toml
@@ -29,7 +29,7 @@ serde = { workspace = true, features = ["derive", "std"] }
signature = { workspace = true }
sqlite = { workspace = true, features = ["bundled"], optional = true }
ssh-key = { version = "0.6.3", default-features = false, features = ["std", "encryption", "getrandom"], optional = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }
zeroize = { workspace = true }

[dev-dependencies]
modified crates/radicle-fetch/Cargo.toml
@@ -22,4 +22,4 @@ nonempty = { workspace = true }
radicle = { workspace = true }
radicle-oid = { workspace = true, features = ["gix"] }
radicle-git-ref-format = { workspace = true, features = ["bstr"] }
-
thiserror = { workspace = true }

\ No newline at end of file
+
thiserror = { workspace = true, default-features = true }

\ No newline at end of file
modified crates/radicle-git-metadata/Cargo.toml
@@ -10,4 +10,4 @@ keywords = ["radicle", "git", "metadata"]
rust-version.workspace = true

[dependencies]
-
thiserror = { workspace = true }

\ No newline at end of file
+
thiserror = { workspace = true, default-features = true }

\ No newline at end of file
modified crates/radicle-node/Cargo.toml
@@ -41,7 +41,7 @@ snapbox = { workspace = true, optional = true }
socket2 = { version = "0.5.7", features = ["all"], optional = true }
structured-logger = { version = "1.0.4", optional = true }
tempfile = { workspace = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }

[target.'cfg(target_os = "linux")'.dependencies]
radicle-systemd = { workspace = true, optional = true }
modified crates/radicle-protocol/Cargo.toml
@@ -27,7 +27,7 @@ sqlite = { workspace = true, features = ["bundled"] }
scrypt = { version = "0.11.0", default-features = false }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["preserve_order"] }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }

[dev-dependencies]
paste = "1.0.15"
modified crates/radicle-remote-helper/Cargo.toml
@@ -19,4 +19,4 @@ log = { workspace = true }
radicle = { workspace = true }
radicle-cli = { workspace = true }
radicle-crypto = { workspace = true }
-
thiserror = { workspace = true }

\ No newline at end of file
+
thiserror = { workspace = true, default-features = true }

\ No newline at end of file
modified crates/radicle-ssh/Cargo.toml
@@ -14,7 +14,7 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }
zeroize = { workspace = true }

[target.'cfg(windows)'.dependencies]
modified crates/radicle-term/Cargo.toml
@@ -20,7 +20,7 @@ inquire = { version = "0.7.4", default-features = false, features = [
    "crossterm",
    "editor",
] }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }
unicode-display-width = "0.3.0"
unicode-segmentation = "1.7.1"
zeroize = { workspace = true }
modified crates/radicle/Cargo.toml
@@ -45,7 +45,7 @@ serde-untagged = "0.1.7"
siphasher = "1.0.0"
sqlite = { workspace = true, features = ["bundled"] }
tempfile = { workspace = true, optional = true }
-
thiserror = { workspace = true }
+
thiserror = { workspace = true, default-features = true }
unicode-normalization = { version = "0.1" }

[target.'cfg(unix)'.dependencies]